Refactor some code into maybe_apply_dentry()
authorEric Biggers <ebiggers3@gmail.com>
Wed, 19 Dec 2012 19:35:44 +0000 (13:35 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 19 Dec 2012 19:35:44 +0000 (13:35 -0600)
src/extract_image.c
src/ntfs-apply.c
src/wimlib_internal.h

index bebd1d32d71b883d6dc20cbb849cffa39c097bc9..f15ffe7dc8a930e076fba071847d2ea4ea9d0491 100644 (file)
@@ -283,25 +283,8 @@ static int extract_directory(const char *output_path, bool is_root)
 static int apply_dentry_normal(struct dentry *dentry, void *arg)
 {
        struct apply_args *args = arg;
-       int extract_flags = args->extract_flags;
        struct inode *inode = dentry->d_inode;
        size_t len;
-       int ret;
-
-       if (dentry->is_extracted)
-               return 0;
-
-       if (extract_flags & WIMLIB_EXTRACT_FLAG_NO_STREAMS)
-               if (inode_unnamed_lte_resolved(inode))
-                       return 0;
-
-       if ((extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE) &&
-            args->progress_func)
-       {
-               args->progress.extract.cur_path = dentry->full_path_utf8;
-               args->progress_func(WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY,
-                                   &args->progress);
-       }
 
        len = strlen(args->target);
        char output_path[len + dentry->full_path_utf8_len + 1];
@@ -310,14 +293,11 @@ static int apply_dentry_normal(struct dentry *dentry, void *arg)
        output_path[len + dentry->full_path_utf8_len] = '\0';
 
        if (inode_is_symlink(inode))
-               ret = extract_symlink(dentry, args, output_path);
+               return extract_symlink(dentry, args, output_path);
        else if (inode_is_directory(inode))
-               ret = extract_directory(output_path, false);
+               return extract_directory(output_path, false);
        else
-               ret = extract_regular_file(dentry, args, output_path);
-       if (ret == 0)
-               dentry->is_extracted = 1;
-       return ret;
+               return extract_regular_file(dentry, args, output_path);
 }
 
 /* Apply timestamp to extracted file */
@@ -361,6 +341,30 @@ static int apply_dentry_timestamps_normal(struct dentry *dentry, void *arg)
        return 0;
 }
 
+static int maybe_apply_dentry(struct dentry *dentry, void *arg)
+{
+       struct apply_args *args = arg;
+       int ret;
+
+       if (dentry->is_extracted)
+               return 0;
+
+       if (args->extract_flags & WIMLIB_EXTRACT_FLAG_NO_STREAMS)
+               if (inode_unnamed_lte_resolved(dentry->d_inode))
+                       return 0;
+
+       if ((args->extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE) &&
+            args->progress_func) {
+               args->progress.extract.cur_path = dentry->full_path_utf8;
+               args->progress_func(WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY,
+                                   &args->progress);
+       }
+       ret = args->apply_dentry(dentry, args);
+       if (ret == 0)
+               dentry->is_extracted = 1;
+       return ret;
+}
+
 static int cmp_streams_by_wim_position(const void *p1, const void *p2)
 {
        const struct lookup_table_entry *lte1, *lte2;
@@ -542,7 +546,7 @@ static int apply_stream_list(struct list_head *stream_list,
                list_for_each_entry(inode, &lte->inode_list, lte_inode_list) {
                        /* For each dentry that points to the inode */
                        inode_for_each_dentry(dentry, inode) {
-                               ret = ops->apply_dentry(dentry, args);
+                               ret = maybe_apply_dentry(dentry, args);
                                if (ret != 0)
                                        goto out;
                                if (progress_func &&
@@ -639,7 +643,8 @@ static int extract_single_image(WIMStruct *w, int image,
        }
 
        args.extract_flags |= WIMLIB_EXTRACT_FLAG_NO_STREAMS;
-       ret = for_dentry_in_tree(wim_root_dentry(w), ops->apply_dentry, &args);
+       args.apply_dentry = ops->apply_dentry;
+       ret = for_dentry_in_tree(wim_root_dentry(w), maybe_apply_dentry, &args);
        args.extract_flags &= ~WIMLIB_EXTRACT_FLAG_NO_STREAMS;
        if (ret != 0)
                goto out;
index cb64baa6af60189239dffde0594047a628423cee..214ac2d617688a8049852f4dcf8bbd5d71930969 100644 (file)
@@ -385,7 +385,7 @@ static int do_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni,
        bool is_hardlink = false;
        ntfs_volume *vol = dir_ni->vol;
        struct inode *inode = dentry->d_inode;
-       dentry->is_extracted = true;
+       dentry->is_extracted = 1;
 
        if (inode->attributes & FILE_ATTRIBUTE_DIRECTORY) {
                type = S_IFDIR;
@@ -580,30 +580,9 @@ static int apply_root_dentry_ntfs(const struct dentry *dentry,
 int apply_dentry_ntfs(struct dentry *dentry, void *arg)
 {
        struct apply_args *args = arg;
-       ntfs_volume *vol             = args->vol;
-       int extract_flags            = args->extract_flags;
-       WIMStruct *w                 = args->w;
+       ntfs_volume *vol = args->vol;
+       WIMStruct *w = args->w;
        ntfs_inode *dir_ni;
-       char *p;
-       char orig;
-       const char *dir_name;
-
-       if (dentry->is_extracted)
-               return 0;
-
-       if (extract_flags & WIMLIB_EXTRACT_FLAG_NO_STREAMS)
-               if (inode_unnamed_lte_resolved(dentry->d_inode))
-                       return 0;
-
-       DEBUG("Applying dentry `%s' to NTFS", dentry->full_path_utf8);
-
-       if ((extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE) &&
-            args->progress_func)
-       {
-               args->progress.extract.cur_path = dentry->full_path_utf8;
-               args->progress_func(WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY,
-                                   &args->progress);
-       }
 
        if (dentry_is_root(dentry))
                return apply_root_dentry_ntfs(dentry, vol, w);
index c2457b9ac51e254ce72fdff8f25e4b89a935c55f..99b2a5aabb0646b6bb98bfeea189970fabaf77cb 100644 (file)
@@ -434,6 +434,7 @@ struct apply_args {
 #endif
        struct list_head empty_files;
        wimlib_progress_func_t progress_func;
+       int (*apply_dentry)(struct dentry *, void *);
 };
 
 extern int apply_dentry_ntfs(struct dentry *dentry, void *arg);