]> wimlib.net Git - wimlib/blobdiff - src/unix_capture.c
unix_capture_symlink(): De-indent
[wimlib] / src / unix_capture.c
index dd79b658e0238cc9f15ed3d039ef1285e2dc9015..1de0b80b1aaed2c5a826ed63e1144a8074df6c65 100644 (file)
@@ -141,6 +141,7 @@ unix_capture_symlink(struct wim_dentry **root_p,
 {
        char deref_name_buf[4096];
        ssize_t deref_name_len;
+       char *dest;
        int ret;
 
        inode->i_attributes = FILE_ATTRIBUTE_REPARSE_POINT;
@@ -151,51 +152,50 @@ unix_capture_symlink(struct wim_dentry **root_p,
         * that contains a relative or absolute symbolic link. */
        deref_name_len = readlink(path, deref_name_buf,
                                  sizeof(deref_name_buf) - 1);
-       if (deref_name_len >= 0) {
-               char *dest = deref_name_buf;
+       if (deref_name_len < 0) {
+               ERROR_WITH_ERRNO("Failed to read target of "
+                                "symbolic link `%s'", path);
+               return WIMLIB_ERR_READLINK;
+       }
 
-               dest[deref_name_len] = '\0';
-               DEBUG("Read symlink `%s'", dest);
+       dest = deref_name_buf;
 
-               if ((params->add_flags & WIMLIB_ADD_FLAG_RPFIX) &&
-                    dest[0] == '/')
-               {
-                       dest = capture_fixup_absolute_symlink(dest,
-                                                             params->capture_root_ino,
-                                                             params->capture_root_dev);
-                       if (dest == NULL) {
-                               /* RPFIX (reparse point fixup) mode:  Ignore
-                                * absolute symbolic link that points out of the
-                                * tree to be captured.  */
-                               free_dentry(*root_p);
-                               *root_p = NULL;
-                               params->progress.scan.cur_path = path;
-                               params->progress.scan.symlink_target = deref_name_buf;
-                               do_capture_progress(params,
-                                                   WIMLIB_SCAN_DENTRY_EXCLUDED_SYMLINK,
-                                                   NULL);
-                               return 0;
-                       }
-                       inode->i_not_rpfixed = 0;
-               }
-               ret = wim_inode_set_symlink(inode, dest, params->lookup_table);
-               if (ret == 0) {
-                       /* Unfortunately, Windows seems to have the concept of
-                        * "file" symbolic links as being different from
-                        * "directory" symbolic links...  so
-                        * FILE_ATTRIBUTE_DIRECTORY needs to be set on the
-                        * symbolic link if the *target* of the symbolic link is
-                        * a directory.  */
-                       struct stat stbuf;
-                       if (stat(path, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
-                               inode->i_attributes |= FILE_ATTRIBUTE_DIRECTORY;
+       dest[deref_name_len] = '\0';
+       DEBUG("Read symlink `%s'", dest);
+
+       if ((params->add_flags & WIMLIB_ADD_FLAG_RPFIX) &&
+            dest[0] == '/')
+       {
+               dest = capture_fixup_absolute_symlink(dest,
+                                                     params->capture_root_ino,
+                                                     params->capture_root_dev);
+               if (dest == NULL) {
+                       /* RPFIX (reparse point fixup) mode:  Ignore
+                        * absolute symbolic link that points out of the
+                        * tree to be captured.  */
+                       free_dentry(*root_p);
+                       *root_p = NULL;
+                       params->progress.scan.cur_path = path;
+                       params->progress.scan.symlink_target = deref_name_buf;
+                       do_capture_progress(params,
+                                           WIMLIB_SCAN_DENTRY_EXCLUDED_SYMLINK,
+                                           NULL);
+                       return 0;
                }
-       } else {
-               ERROR_WITH_ERRNO("Failed to read target of "
-                                "symbolic link `%s'", path);
-               ret = WIMLIB_ERR_READLINK;
+               inode->i_not_rpfixed = 0;
        }
-       return ret;
+       ret = wim_inode_set_symlink(inode, dest, params->lookup_table);
+       if (ret)
+               return ret;
+
+       /* Unfortunately, Windows seems to have the concept of "file" symbolic
+        * links as being different from "directory" symbolic links...  so
+        * FILE_ATTRIBUTE_DIRECTORY needs to be set on the symbolic link if the
+        * *target* of the symbolic link is a directory.  */
+       struct stat stbuf;
+       if (stat(path, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
+               inode->i_attributes |= FILE_ATTRIBUTE_DIRECTORY;
+       return 0;
 }
 
 static int
@@ -209,7 +209,10 @@ unix_build_dentry_tree_recursive(struct wim_dentry **root_ret,
        struct wim_inode *inode = NULL;
        struct stat stbuf;
 
-       if (exclude_path(path, path_len, params->config, true)) {
+       if (should_exclude_path(path + params->capture_root_nchars,
+                               path_len - params->capture_root_nchars,
+                               params->config))
+       {
                ret = 0;
                goto out_progress;
        }
@@ -242,9 +245,10 @@ unix_build_dentry_tree_recursive(struct wim_dentry **root_ret,
                goto out;
        }
 
-       ret = inode_table_new_dentry(&params->inode_table,
+       ret = inode_table_new_dentry(params->inode_table,
                                     path_basename_with_len(path, path_len),
-                                    stbuf.st_ino, stbuf.st_dev, false, &root);
+                                    stbuf.st_ino, stbuf.st_dev,
+                                    S_ISDIR(stbuf.st_mode), &root);
        if (ret)
                goto out;
 
@@ -341,13 +345,6 @@ unix_build_dentry_tree(struct wim_dentry **root_ret,
                        return WIMLIB_ERR_STAT;
                }
 
-               if ((params->add_flags & WIMLIB_ADD_FLAG_ROOT) &&
-                   !S_ISDIR(root_stbuf.st_mode))
-               {
-                       ERROR("Root of capture \"%s\" is not a directory",
-                             root_disk_path);
-                       return WIMLIB_ERR_NOTDIR;
-               }
                params->capture_root_ino = root_stbuf.st_ino;
                params->capture_root_dev = root_stbuf.st_dev;
        }
@@ -363,6 +360,8 @@ unix_build_dentry_tree(struct wim_dentry **root_ret,
                return WIMLIB_ERR_NOMEM;
        memcpy(path_buf, root_disk_path, path_len + 1);
 
+       params->capture_root_nchars = path_len;
+
        ret = unix_build_dentry_tree_recursive(root_ret, path_buf,
                                               path_len, params);
        FREE(path_buf);