Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 40997a95000af2a802d4531dd07d01c6 > files > 1

febootstrap-3.4-2.fc15.src.rpm

From b6cce31ec4d8232d6400fe4fe915f53d285a3b4f Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones@redhat.com>
Date: Wed, 20 Apr 2011 11:35:19 +0100
Subject: [PATCH] helper: Don't fail if objects are created in a symlinked dir
 (RHBZ#698089).

---
 helper/ext2.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/helper/ext2.c b/helper/ext2.c
index 2fc8036..705facc 100644
--- a/helper/ext2.c
+++ b/helper/ext2.c
@@ -402,6 +402,20 @@ ext2_file_stat (const char *orig_filename, const struct stat *statbuf)
     dirname = strndup (orig_filename, p-orig_filename);
     basename = p+1;
 
+    /* If the parent directory is a symlink to another directory, then
+     * we want to look up the target directory. (RHBZ#698089).
+     */
+    struct stat stat1, stat2;
+    if (lstat (dirname, &stat1) == 0 && S_ISLNK (stat1.st_mode) &&
+        stat (dirname, &stat2) == 0 && S_ISDIR (stat2.st_mode)) {
+      char *new_dirname = malloc (PATH_MAX+1);
+      ssize_t r = readlink (dirname, new_dirname, PATH_MAX+1);
+      if (r == -1)
+        error (EXIT_FAILURE, errno, "readlink: %s", orig_filename);
+      new_dirname[r] = '\0';
+      dirname = new_dirname;
+    }
+
     /* Look up the parent directory. */
     err = ext2fs_namei (fs, EXT2_ROOT_INO, EXT2_ROOT_INO, dirname, &dir_ino);
     if (err != 0)
-- 
1.7.4.4