Move VERBOSE flags to progress callbacks
authorEric Biggers <ebiggers3@gmail.com>
Thu, 22 Nov 2012 02:17:09 +0000 (20:17 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 22 Nov 2012 02:17:09 +0000 (20:17 -0600)
programs/imagex.c
src/extract.c
src/modify.c
src/ntfs-apply.c
src/ntfs-capture.c
src/wimlib.h
src/wimlib_internal.h

index 2350f7e..61a93fb 100644 (file)
@@ -363,6 +363,12 @@ static int imagex_progress_func(enum wimlib_progress_msg msg,
        case WIMLIB_PROGRESS_MSG_SCAN_BEGIN:
                printf("Scanning `%s'...\n", info->scan.source);
                break;
+       case WIMLIB_PROGRESS_MSG_SCAN_DENTRY:
+               if (info->scan.excluded)
+                       printf("Excluding `%s' from capture\n", info->scan.cur_path);
+               else
+                       printf("Scanning `%s'\n", info->scan.cur_path);
+               break;
        /*case WIMLIB_PROGRESS_MSG_SCAN_END:*/
                /*break;*/
        case WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY:
@@ -413,6 +419,9 @@ static int imagex_progress_func(enum wimlib_progress_msg msg,
                if (info->extract.completed_bytes == info->extract.total_bytes)
                        putchar('\n');
                break;
+       case WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY:
+               puts(info->extract.cur_path);
+               break;
        case WIMLIB_PROGRESS_MSG_JOIN_STREAMS:
                percent_done = TO_PERCENT(info->join.completed_bytes,
                                          info->join.total_bytes);
index a3f00cc..a3942cf 100644 (file)
@@ -298,8 +298,13 @@ static int apply_dentry_normal(struct dentry *dentry, void *arg)
                if (inode_unnamed_lte_resolved(inode))
                        return 0;
 
-       if (extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE)
-               puts(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);
+       }
 
        len = strlen(args->target);
        char output_path[len + dentry->full_path_utf8_len + 1];
@@ -569,6 +574,7 @@ static int extract_single_image(WIMStruct *w, int image,
        args.num_lutimes_warnings = 0;
        args.target               = target;
        args.stream_list          = &stream_list;
+       args.progress_func        = progress_func;
 
        if (progress_func) {
                args.progress.extract.image      = image;
index a8ce13c..3403eb3 100644 (file)
@@ -96,7 +96,8 @@ static int build_dentry_tree(struct dentry **root_ret,
                             struct lookup_table *lookup_table,
                             struct wim_security_data *sd,
                             const struct capture_config *config,
-                            int add_flags,
+                            int add_image_flags,
+                            wimlib_progress_func_t progress_func,
                             void *extra_arg)
 {
        struct stat root_stbuf;
@@ -107,33 +108,43 @@ static int build_dentry_tree(struct dentry **root_ret,
        struct inode *inode;
 
        if (exclude_path(root_disk_path, config, true)) {
-               if (add_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) {
+               if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) {
                        ERROR("Cannot exclude the root directory from capture");
                        return WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
                }
-               if (add_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
-                       printf("Excluding file `%s' from capture\n",
-                              root_disk_path);
+               if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+                   && progress_func)
+               {
+                       union wimlib_progress_info info;
+                       info.scan.cur_path = root_disk_path;
+                       info.scan.excluded = true;
+                       progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
+               }
                *root_ret = NULL;
                return 0;
        }
 
+       if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+           && progress_func)
+       {
+               union wimlib_progress_info info;
+               info.scan.cur_path = root_disk_path;
+               info.scan.excluded = false;
+               progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
+       }
 
-       if (add_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)
+       if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)
                stat_fn = stat;
        else
                stat_fn = lstat;
 
-       if (add_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
-               printf("Scanning `%s'\n", root_disk_path);
-
        ret = (*stat_fn)(root_disk_path, &root_stbuf);
        if (ret != 0) {
                ERROR_WITH_ERRNO("Failed to stat `%s'", root_disk_path);
                return WIMLIB_ERR_STAT;
        }
 
-       if ((add_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) &&
+       if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) &&
              !S_ISDIR(root_stbuf.st_mode)) {
                ERROR("`%s' is not a directory", root_disk_path);
                return WIMLIB_ERR_NOTDIR;
@@ -145,7 +156,7 @@ static int build_dentry_tree(struct dentry **root_ret,
                return WIMLIB_ERR_SPECIAL_FILE;
        }
 
-       if (add_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT)
+       if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT)
                filename = "";
        else
                filename = path_basename(root_disk_path);
@@ -165,7 +176,7 @@ static int build_dentry_tree(struct dentry **root_ret,
                inode->ino = (u64)root_stbuf.st_ino |
                                   ((u64)root_stbuf.st_dev << ((sizeof(ino_t) * 8) & 63));
 
-       add_flags &= ~WIMLIB_ADD_IMAGE_FLAG_ROOT;
+       add_image_flags &= ~WIMLIB_ADD_IMAGE_FLAG_ROOT;
        inode->resolved = true;
 
        if (S_ISREG(root_stbuf.st_mode)) { /* Archiving a regular file */
@@ -255,8 +266,8 @@ static int build_dentry_tree(struct dentry **root_ret,
                                        continue;
                        strcpy(name + len + 1, p->d_name);
                        ret = build_dentry_tree(&child, name, lookup_table,
-                                               NULL, config,
-                                               add_flags, NULL);
+                                               NULL, config, add_image_flags,
+                                               progress_func, NULL);
                        if (ret != 0)
                                break;
                        if (child)
@@ -953,7 +964,7 @@ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source,
                            struct lookup_table *,
                            struct wim_security_data *,
                            const struct capture_config *,
-                           int, void *);
+                           int, wimlib_progress_func_t, void *);
        void *extra_arg;
 
        struct dentry *root_dentry = NULL;
@@ -1033,7 +1044,7 @@ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *source,
        DEBUG("Building dentry tree.");
        ret = (*capture_tree)(&root_dentry, source, w->lookup_table, sd,
                              &config, add_image_flags | WIMLIB_ADD_IMAGE_FLAG_ROOT,
-                             extra_arg);
+                             progress_func, extra_arg);
        destroy_capture_config(&config);
 
        if (ret != 0) {
index 61199b8..7522ec8 100644 (file)
@@ -600,10 +600,16 @@ int wim_apply_dentry_ntfs(struct dentry *dentry, void *arg)
                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)
-               puts(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 wim_apply_root_dentry_ntfs(dentry, vol, w);
index c4770a5..aa4458c 100644 (file)
@@ -405,7 +405,8 @@ struct readdir_ctx {
        struct sd_set       *sd_set;
        const struct capture_config *config;
        ntfs_volume        **ntfs_vol_p;
-       int                  flags;
+       int                  add_image_flags;
+       wimlib_progress_func_t progress_func;
 };
 
 static int
@@ -416,7 +417,8 @@ build_dentry_tree_ntfs_recursive(struct dentry **root_p, ntfs_inode *dir_ni,
                                 struct sd_set *sd_set,
                                 const struct capture_config *config,
                                 ntfs_volume **ntfs_vol_p,
-                                int flags);
+                                int add_image_flags,
+                                wimlib_progress_func_t progress_func);
 
 static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
                                    const int name_len, const int name_type,
@@ -463,7 +465,8 @@ static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
                                               ni, ctx->path, path_len, name_type,
                                               ctx->lookup_table, ctx->sd_set,
                                               ctx->config, ctx->ntfs_vol_p,
-                                              ctx->flags);
+                                              ctx->add_image_flags,
+                                              ctx->progress_func);
 
        if (child)
                dentry_add_child(ctx->parent, child);
@@ -506,7 +509,8 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
                                            struct sd_set *sd_set,
                                            const struct capture_config *config,
                                            ntfs_volume **ntfs_vol_p,
-                                           int flags)
+                                           int add_image_flags,
+                                           wimlib_progress_func_t progress_func)
 {
        u32 attributes;
        int mrec_flags;
@@ -514,6 +518,19 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
        char dos_name_utf8[64];
        struct dentry *root;
 
+       if (exclude_path(path, config, false)) {
+               if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+                   && progress_func)
+               {
+                       union wimlib_progress_info info;
+                       info.scan.cur_path = path;
+                       info.scan.excluded = true;
+                       progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
+               }
+               *root_p = NULL;
+               return 0;
+       }
+
        mrec_flags = ni->mrec->flags;
        struct SECURITY_CONTEXT ctx;
        memset(&ctx, 0, sizeof(ctx));
@@ -527,23 +544,15 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
                return WIMLIB_ERR_NTFS_3G;
        }
 
-       if (exclude_path(path, config, false)) {
-               if (flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE) {
-                       const char *file_type;
-                       if (attributes & MFT_RECORD_IS_DIRECTORY)
-                               file_type = "directory";
-                       else
-                               file_type = "file";
-                       printf("Excluding %s `%s' from capture\n",
-                              file_type, path);
-               }
-               *root_p = NULL;
-               return 0;
+       if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+           && progress_func)
+       {
+               union wimlib_progress_info info;
+               info.scan.cur_path = path;
+               info.scan.excluded = false;
+               progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
        }
 
-       if (flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
-               printf("Scanning `%s'\n", path);
-
        root = new_dentry_with_timeless_inode(path_basename(path));
        if (!root)
                return WIMLIB_ERR_NOMEM;
@@ -596,7 +605,8 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
                        .sd_set       = sd_set,
                        .config       = config,
                        .ntfs_vol_p   = ntfs_vol_p,
-                       .flags        = flags,
+                       .add_image_flags = add_image_flags,
+                       .progress_func = progress_func,
                };
                ret = ntfs_readdir(ni, &pos, &ctx, wim_ntfs_capture_filldir);
                if (ret != 0) {
@@ -648,7 +658,8 @@ int build_dentry_tree_ntfs(struct dentry **root_p,
                           struct lookup_table *lookup_table,
                           struct wim_security_data *sd,
                           const struct capture_config *config,
-                          int flags,
+                          int add_image_flags,
+                          wimlib_progress_func_t progress_func,
                           void *extra_arg)
 {
        ntfs_volume *vol;
@@ -697,7 +708,8 @@ int build_dentry_tree_ntfs(struct dentry **root_p,
        ret = build_dentry_tree_ntfs_recursive(root_p, NULL, root_ni, path, 1,
                                               FILE_NAME_POSIX, lookup_table,
                                               &sd_set, config, ntfs_vol_p,
-                                              flags);
+                                              add_image_flags,
+                                              progress_func);
 out_cleanup:
        FREE(path);
        ntfs_inode_close(root_ni);
index 0dd705c..1957f6b 100644 (file)
@@ -263,6 +263,11 @@ enum wimlib_progress_msg {
         * info will point to ::wimlib_progress_info.extract. */
        WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS,
 
+       /** A file or directory is being extracted.  @a info will point to
+        * ::wimlib_progress_info.extract, and the @a cur_path member will be
+        * valid. */
+       WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY,
+
        /** All the WIM files and directories have been extracted, and
         * timestamps are about to be applied.  @a info will point to
         * ::wimlib_progress_info.extract. */
@@ -277,6 +282,12 @@ enum wimlib_progress_msg {
         * ::wimlib_progress_info.scan. */
        WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
 
+       /** A directory or file is being scanned.  @a info will point to
+        * ::wimlib_progress_info.scan, and its @a cur_path member will be
+        * valid.  This message is only sent if ::WIMLIB_ADD_IMAGE_FLAG_VERBOSE
+        * is passed to wimlib_add_image(). */
+       WIMLIB_PROGRESS_MSG_SCAN_DENTRY,
+
        /** The directory or NTFS volume has been successfully scanned, and a
         * tree of WIM dentries has been built in-memory. @a info will point to
         * ::wimlib_progress_info.scan. */
@@ -375,6 +386,15 @@ union wimlib_progress_info {
        struct wimlib_progress_info_scan {
                /** Directory or NTFS volume that is being scanned. */
                const char *source;
+
+               /** Path to the file or directory that is about to be scanned,
+                * relative to the root of the image capture or the NTFS volume.
+                * */
+               const char *cur_path;
+
+               /** True iff @a cur_path is being excluded from the image
+                * capture due to the capture configuration file. */
+               bool excluded;
        } scan;
 
        /** Valid on messages ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN,
@@ -393,6 +413,10 @@ union wimlib_progress_info {
                 * extracted. */
                const char *target;
 
+               /** Current dentry being extracted.  (Valid only if message is
+                * ::WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY.) */
+               const char *cur_path;
+
                /** Number of bytes of uncompressed data that will be extracted.
                 * Takes into account hard links (they are not counted for each
                 * link.)
@@ -517,8 +541,9 @@ typedef int (*wimlib_progress_func_t)(enum wimlib_progress_msg msg_type,
  * with ::WIMLIB_ADD_IMAGE_FLAG_NTFS. */
 #define WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE              0x00000002
 
-/** Print the name of each file or directory as it is scanned to be included in
- * the WIM image. */
+/** Call the progress function with the message
+ * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY when each directory or file is starting to
+ * be scanned. */
 #define WIMLIB_ADD_IMAGE_FLAG_VERBOSE                  0x00000004
 
 /** Mark the image being added as the bootable image of the WIM. */
@@ -547,8 +572,10 @@ typedef int (*wimlib_progress_func_t)(enum wimlib_progress_msg msg_type,
  * together.  Cannot be used with ::WIMLIB_EXTRACT_FLAG_NTFS. */
 #define WIMLIB_EXTRACT_FLAG_SYMLINK                    0x00000004
 
-/** Print the name of each file or directory as it is extracted from the WIM
- * image. */
+/** Call the progress function with the argument
+ * ::WIMLIB_PROGRESS_MSG_EXTRACT_DENTRY each time a file or directory is
+ * extracted.  Note: these calls will be interspersed with calls for the message
+ * ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS. */
 #define WIMLIB_EXTRACT_FLAG_VERBOSE                    0x00000008
 
 /** Read the WIM file sequentially while extracting the image. */
index 8782995..b0a0aa2 100644 (file)
@@ -454,19 +454,21 @@ struct apply_args {
        struct _ntfs_volume *vol;
 #endif
        struct list_head empty_files;
+       wimlib_progress_func_t progress_func;
 };
 
 extern int wim_apply_dentry_ntfs(struct dentry *dentry, void *arg);
 extern int wim_apply_dentry_timestamps(struct dentry *dentry, void *arg);
 
 /* ntfs-capture.c */
-int build_dentry_tree_ntfs(struct dentry **root_p,
-                          const char *device,
-                          struct lookup_table *lookup_table,
-                          struct wim_security_data *sd,
-                          const struct capture_config *config,
-                          int flags,
-                          void *extra_arg);
+extern int build_dentry_tree_ntfs(struct dentry **root_p,
+                                 const char *device,
+                                 struct lookup_table *lookup_table,
+                                 struct wim_security_data *sd,
+                                 const struct capture_config *config,
+                                 int add_image_flags,
+                                 wimlib_progress_func_t progress_func,
+                                 void *extra_arg);
 
 /* resource.c */
 extern const u8 *get_resource_entry(const u8 *p, struct resource_entry *entry);