]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
wimexport: Add --recompress option
[wimlib] / programs / imagex.c
index 6351475f5178494656bd5f653d2432d8c918c588..1c077b7f2fae1afb1db12fc53cf0c99b8894c4a1 100644 (file)
@@ -46,6 +46,8 @@
 #  include <alloca.h>
 #endif
 
+#define WIMLIB_COMPRESSION_TYPE_INVALID (-1)
+
 #ifdef __WIN32__
 #  include "imagex-win32.h"
 #  define print_security_descriptor     win32_print_security_descriptor
@@ -166,7 +168,7 @@ enum {
        IMAGEX_NO_ACLS_OPTION,
        IMAGEX_NO_ATTRIBUTES_OPTION,
        IMAGEX_NO_REPLACE_OPTION,
-       IMAGEX_NO_WILDCARDS_OPTION,
+       IMAGEX_NO_GLOBS_OPTION,
        IMAGEX_NULLGLOB_OPTION,
        IMAGEX_ONE_FILE_ONLY_OPTION,
        IMAGEX_PACK_CHUNK_SIZE_OPTION,
@@ -269,6 +271,7 @@ static const struct option export_options[] = {
        {T("nocheck"),     no_argument,       NULL, IMAGEX_NOCHECK_OPTION},
        {T("no-check"),    no_argument,       NULL, IMAGEX_NOCHECK_OPTION},
        {T("compress"),    required_argument, NULL, IMAGEX_COMPRESS_OPTION},
+       {T("recompress"),  no_argument,       NULL, IMAGEX_RECOMPRESS_OPTION},
        {T("compress-slow"), no_argument,     NULL, IMAGEX_COMPRESS_SLOW_OPTION},
        {T("pack-streams"),no_argument,       NULL, IMAGEX_PACK_STREAMS_OPTION},
        {T("solid"),       no_argument,       NULL, IMAGEX_PACK_STREAMS_OPTION},
@@ -298,7 +301,8 @@ static const struct option extract_options[] = {
        {T("dest-dir"),    required_argument, NULL, IMAGEX_DEST_DIR_OPTION},
        {T("to-stdout"),   no_argument,       NULL, IMAGEX_TO_STDOUT_OPTION},
        {T("include-invalid-names"), no_argument, NULL, IMAGEX_INCLUDE_INVALID_NAMES_OPTION},
-       {T("no-wildcards"), no_argument,      NULL, IMAGEX_NO_WILDCARDS_OPTION},
+       {T("no-wildcards"), no_argument,      NULL, IMAGEX_NO_GLOBS_OPTION},
+       {T("no-globs"),     no_argument,      NULL, IMAGEX_NO_GLOBS_OPTION},
        {T("nullglob"),     no_argument,      NULL, IMAGEX_NULLGLOB_OPTION},
        {T("preserve-dir-structure"), no_argument, NULL, IMAGEX_PRESERVE_DIR_STRUCTURE_OPTION},
        {T("wimboot"),     no_argument,       NULL, IMAGEX_WIMBOOT_OPTION},
@@ -365,6 +369,7 @@ static const struct option unmount_options[] = {
        {T("check"),   no_argument, NULL, IMAGEX_CHECK_OPTION},
        {T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
        {T("lazy"),    no_argument, NULL, IMAGEX_LAZY_OPTION},
+       {T("force"),    no_argument, NULL, IMAGEX_FORCE_OPTION},
        {T("new-image"), no_argument, NULL, IMAGEX_NEW_IMAGE_OPTION},
        {NULL, 0, NULL, 0},
 };
@@ -504,7 +509,6 @@ set_compress_slow(void)
                                .nice_match_length = 96,
                                .num_optim_passes = 4,
                                .max_search_depth = 100,
-                               .max_matches_per_pos = 10,
                                .main_nostat_cost = 15,
                                .len_nostat_cost = 15,
                                .aligned_nostat_cost = 7,
@@ -520,7 +524,6 @@ set_compress_slow(void)
                .max_match_length = UINT32_MAX,
                .nice_match_length = 96,
                .max_search_depth = 100,
-               .max_matches_per_pos = 10,
                .optim_array_length = 1024,
        };
 
@@ -1078,24 +1081,13 @@ imagex_progress_func(enum wimlib_progress_msg msg,
                        imagex_printf(T("\nWARNING: Excluding unsupported file or directory\n"
                                        "         \"%"TS"\" from capture\n"), info->scan.cur_path);
                        break;
-               case WIMLIB_SCAN_DENTRY_EXCLUDED_SYMLINK:
-                       imagex_printf(T("\nWARNING: Ignoring absolute symbolic link "
-                                       "with out-of-tree target:\n"
-                                       "           \"%"TS"\" => \"%"TS"\"\n"
-                                       "           (Use --norpfix to capture "
-                                       "absolute symbolic links as-is)\n"),
-                                       info->scan.cur_path, info->scan.symlink_target);
-                       break;
                case WIMLIB_SCAN_DENTRY_FIXED_SYMLINK:
                        /* Symlink fixups are enabled by default.  This is
                         * mainly intended for Windows, which for some reason
                         * uses absolute junctions (with drive letters!) in the
                         * default installation.  On UNIX-like systems, warn the
                         * user when fixing the target of an absolute symbolic
-                        * link, so they know to disable this if they want.
-                        * (Although, more likely they will get the warning
-                        * about an absolute symbolic link with an out-of-tree
-                        * target first.)  */
+                        * link, so they know to disable this if they want.  */
                #ifndef __WIN32__
                        imagex_printf(T("\nWARNING: Adjusted target of "
                                        "absolute symbolic link \"%"TS"\"\n"
@@ -1104,6 +1096,8 @@ imagex_progress_func(enum wimlib_progress_msg msg,
                                        info->scan.cur_path);
                #endif
                        break;
+               default:
+                       break;
                }
                break;
        case WIMLIB_PROGRESS_MSG_SCAN_END:
@@ -1216,6 +1210,20 @@ imagex_progress_func(enum wimlib_progress_msg msg,
                imagex_printf(T("\nExtracting \"%"TS"\" as normal file (not WIMBoot pointer)\n"),
                              info->wimboot_exclude.path_in_wim);
                break;
+       case WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN:
+               if (info->unmount.mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
+                       if (info->unmount.unmount_flags & WIMLIB_UNMOUNT_FLAG_COMMIT) {
+                               imagex_printf(T("Committing changes to %"TS" (image %d)\n"),
+                                             info->unmount.mounted_wim,
+                                             info->unmount.mounted_image);
+                       } else {
+                               imagex_printf(T("Discarding changes to %"TS" (image %d)\n"),
+                                             info->unmount.mounted_wim,
+                                             info->unmount.mounted_image);
+                               imagex_printf(T("\t(Use --commit to keep changes.)\n"));
+                       }
+               }
+               break;
        default:
                break;
        }
@@ -2605,6 +2613,9 @@ imagex_export(int argc, tchar **argv, int cmd)
                        if (compression_type == WIMLIB_COMPRESSION_TYPE_INVALID)
                                goto out_err;
                        break;
+               case IMAGEX_RECOMPRESS_OPTION:
+                       write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
+                       break;
                case IMAGEX_COMPRESS_SLOW_OPTION:
                        write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
                        set_compress_slow();
@@ -2902,7 +2913,7 @@ imagex_extract(int argc, tchar **argv, int cmd)
                        extract_flags |= WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES;
                        extract_flags |= WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS;
                        break;
-               case IMAGEX_NO_WILDCARDS_OPTION:
+               case IMAGEX_NO_GLOBS_OPTION:
                        extract_flags &= ~WIMLIB_EXTRACT_FLAG_GLOB_PATHS;
                        break;
                case IMAGEX_NULLGLOB_OPTION:
@@ -2927,7 +2938,7 @@ imagex_extract(int argc, tchar **argv, int cmd)
        if (!(extract_flags & (WIMLIB_EXTRACT_FLAG_GLOB_PATHS |
                               WIMLIB_EXTRACT_FLAG_STRICT_GLOB)))
        {
-               imagex_error(T("Can't combine --no-wildcards and --nullglob!"));
+               imagex_error(T("Can't combine --no-globs and --nullglob!"));
                goto out_err;
        }
 
@@ -2989,6 +3000,15 @@ imagex_extract(int argc, tchar **argv, int cmd)
                if (!imagex_be_quiet)
                        imagex_printf(T("Done extracting files.\n"));
        } else if (ret == WIMLIB_ERR_PATH_DOES_NOT_EXIST) {
+               if ((extract_flags & (WIMLIB_EXTRACT_FLAG_STRICT_GLOB |
+                                     WIMLIB_EXTRACT_FLAG_GLOB_PATHS))
+                       == (WIMLIB_EXTRACT_FLAG_STRICT_GLOB |
+                           WIMLIB_EXTRACT_FLAG_GLOB_PATHS))
+               {
+                       tfprintf(stderr,
+                                T("Note: You can use the '--nullglob' "
+                                  "option to ignore missing files.\n"));
+               }
                tfprintf(stderr, T("Note: You can use `%"TS"' to see what "
                                   "files and directories\n"
                                   "      are in the WIM image.\n"),
@@ -3673,7 +3693,14 @@ imagex_unmount(int argc, tchar **argv, int cmd)
                        unmount_flags |= WIMLIB_UNMOUNT_FLAG_REBUILD;
                        break;
                case IMAGEX_LAZY_OPTION:
-                       unmount_flags |= WIMLIB_UNMOUNT_FLAG_LAZY;
+               case IMAGEX_FORCE_OPTION:
+                       /* Now, unmount is lazy by default.  However, committing
+                        * the image will fail with
+                        * WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY if there are open
+                        * file descriptors on the WIM image.  The
+                        * WIMLIB_UNMOUNT_FLAG_FORCE option forces these file
+                        * descriptors to be closed.  */
+                       unmount_flags |= WIMLIB_UNMOUNT_FLAG_FORCE;
                        break;
                case IMAGEX_NEW_IMAGE_OPTION:
                        unmount_flags |= WIMLIB_UNMOUNT_FLAG_NEW_IMAGE;
@@ -3693,13 +3720,19 @@ imagex_unmount(int argc, tchar **argv, int cmd)
                                       "without --commit also specified!"));
                        goto out_err;
                }
-               imagex_printf(T("Committing changes as new image...\n"));
        }
 
        ret = wimlib_unmount_image_with_progress(argv[0], unmount_flags,
                                                 imagex_progress_func, NULL);
-       if (ret)
+       if (ret) {
                imagex_error(T("Failed to unmount \"%"TS"\""), argv[0]);
+               if (ret == WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY) {
+                       imagex_printf(T(
+                               "\tNote: Use --commit --force to force changes "
+                                       "to be committed, regardless\n"
+                               "\t      of open files.\n"));
+               }
+       }
 out:
        return ret;
 
@@ -4003,6 +4036,7 @@ T(
 "                    DEST_WIMFILE [DEST_IMAGE_NAME [DEST_IMAGE_DESCRIPTION]]\n"
 "                    [--boot] [--check] [--nocheck] [--compress=TYPE]\n"
 "                    [--ref=\"GLOB\"] [--threads=NUM_THREADS] [--rebuild]\n"
+"                    [--wimboot]\n"
 ),
 [CMD_EXTRACT] =
 T(
@@ -4010,7 +4044,7 @@ T(
 "                    [--check] [--ref=\"GLOB\"] [--dest-dir=CMD_DIR]\n"
 "                    [--to-stdout] [--no-acls] [--strict-acls]\n"
 "                    [--no-attributes] [--include-invalid-names]\n"
-"                    [--no-wildcards] [--nullglob] [--preserve-dir-structure]\n"
+"                    [--no-globs] [--nullglob] [--preserve-dir-structure]\n"
 ),
 [CMD_INFO] =
 T(
@@ -4049,8 +4083,8 @@ T(
 #if WIM_MOUNTING_SUPPORTED
 [CMD_UNMOUNT] =
 T(
-"    %"TS" DIRECTORY [--commit] [--check] [--rebuild] [--lazy]\n"
-"                    [--new-image]\n"
+"    %"TS" DIRECTORY [--commit] [--force] [--new-image]\n"
+"                         [--check] [--rebuild]\n"
 ),
 #endif
 [CMD_UPDATE] =