]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
Add tests for pathlist extraction
[wimlib] / programs / imagex.c
index 347564c55a8c3e4787205dc618f033f93212eee1..aa628b35fbf14a9c37171639493acf50dfe2f6c8 100644 (file)
@@ -142,6 +142,7 @@ enum {
        IMAGEX_NORPFIX_OPTION,
        IMAGEX_NOCHECK_OPTION,
        IMAGEX_NO_ACLS_OPTION,
+       IMAGEX_NO_WILDCARDS_OPTION,
        IMAGEX_NOT_PIPABLE_OPTION,
        IMAGEX_PACK_STREAMS_OPTION,
        IMAGEX_PATH_OPTION,
@@ -157,6 +158,7 @@ enum {
        IMAGEX_STAGING_DIR_OPTION,
        IMAGEX_STREAMS_INTERFACE_OPTION,
        IMAGEX_STRICT_ACLS_OPTION,
+       IMAGEX_STRICT_WILDCARDS_OPTION,
        IMAGEX_SYMLINK_OPTION,
        IMAGEX_THREADS_OPTION,
        IMAGEX_TO_STDOUT_OPTION,
@@ -252,6 +254,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("strict-wildcards"), no_argument,  NULL, IMAGEX_STRICT_WILDCARDS_OPTION},
+       {T("no-wildcards"), no_argument,      NULL, IMAGEX_NO_WILDCARDS_OPTION},
        {NULL, 0, NULL, 0},
 };
 
@@ -2697,8 +2701,10 @@ imagex_extract(int argc, tchar **argv, int cmd)
        int ret;
        const tchar *wimfile;
        const tchar *image_num_or_name;
+       const tchar *pathlist;
        tchar *dest_dir = T(".");
        int extract_flags = WIMLIB_EXTRACT_FLAG_SEQUENTIAL | WIMLIB_EXTRACT_FLAG_NORPFIX;
+       int listfile_extract_flags = WIMLIB_EXTRACT_FLAG_GLOB_PATHS;
 
        STRING_SET(refglobs);
 
@@ -2739,6 +2745,12 @@ 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:
+                       listfile_extract_flags &= ~WIMLIB_EXTRACT_FLAG_GLOB_PATHS;
+                       break;
+               case IMAGEX_STRICT_WILDCARDS_OPTION:
+                       listfile_extract_flags |= WIMLIB_EXTRACT_FLAG_STRICT_GLOB;
+                       break;
                default:
                        goto out_usage;
                }
@@ -2755,10 +2767,17 @@ imagex_extract(int argc, tchar **argv, int cmd)
        argc -= 2;
        argv += 2;
 
-       cmds = prepare_extract_commands(argv, argc, extract_flags, dest_dir,
-                                       &num_cmds);
-       if (!cmds)
-               goto out_err;
+       if (argc == 1 && argv[0][0] == T('@')) {
+               pathlist = argv[0] + 1;
+               cmds = NULL;
+               num_cmds = 0;
+       } else {
+               cmds = prepare_extract_commands(argv, argc, extract_flags, dest_dir,
+                                               &num_cmds);
+               if (cmds == NULL)
+                       goto out_err;
+               pathlist = NULL;
+       }
 
        ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
        if (ret)
@@ -2777,8 +2796,17 @@ imagex_extract(int argc, tchar **argv, int cmd)
                        goto out_wimlib_free;
        }
 
-       ret = wimlib_extract_files(wim, image, cmds, num_cmds, 0,
-                                  imagex_progress_func);
+       ret = 0;
+       if (ret == 0 && cmds != NULL) {
+               ret = wimlib_extract_files(wim, image, cmds, num_cmds, 0,
+                                          imagex_progress_func);
+       }
+       if (ret == 0 && pathlist != NULL) {
+               ret = wimlib_extract_pathlist(wim, image, dest_dir,
+                                             pathlist,
+                                             extract_flags | listfile_extract_flags,
+                                             imagex_progress_func);
+       }
        if (ret == 0) {
                if (!imagex_be_quiet)
                        imagex_printf(T("Done extracting files.\n"));
@@ -2786,7 +2814,7 @@ imagex_extract(int argc, tchar **argv, int cmd)
                tfprintf(stderr, T("Note: You can use `%"TS"' to see what "
                                   "files and directories\n"
                                   "      are in the WIM image.\n"),
-                               get_cmd_string(CMD_INFO, false));
+                               get_cmd_string(CMD_DIR, false));
        } else if (ret == WIMLIB_ERR_RESOURCE_NOT_FOUND) {
                struct wimlib_wim_info info;
 
@@ -3821,9 +3849,9 @@ T(
 [CMD_APPLY] =
 T(
 "    %"TS" WIMFILE [(IMAGE_NUM | IMAGE_NAME | all)]\n"
-"                    (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n"
-"                    [--symlink] [--ref=\"GLOB\"] [--no-acls] [--strict-acls]\n"
-"                    [--rpfix] [--norpfix] [--include-invalid-names]\n"
+"                    (DIRECTORY | NTFS_VOLUME) [--check] [--ref=\"GLOB\"]\n"
+"                    [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
+"                    [--hardlink] [--symlink] [--include-invalid-names]\n"
 ),
 [CMD_CAPTURE] =
 T(
@@ -3980,9 +4008,11 @@ recommend_man_page(int cmd, FILE *fp)
 {
        const tchar *format_str;
 #ifdef __WIN32__
-       format_str = T("See %"TS".pdf in the doc directory for more details.\n");
+       format_str = T("Uncommon options are not listed;\n"
+                      "See %"TS".pdf in the doc directory for more details.\n");
 #else
-       format_str = T("Try `man %"TS"' for more details.\n");
+       format_str = T("Uncommon options are not listed;\n"
+                      "Try `man %"TS"' for more details.\n");
 #endif
        tfprintf(fp, format_str, get_cmd_string(cmd, true));
 }
@@ -4010,7 +4040,6 @@ usage_all(FILE *fp)
 "    %"TS" --version\n"
 "\n"
 "    The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
-"    Uncommon options are not listed; see the documentation for full details.\n"
 "\n"
        );
        tfprintf(fp, extra, invocation_name, invocation_name);
@@ -4057,8 +4086,26 @@ main(int argc, char **argv)
 
                }
        }
+
 #endif /* !__WIN32__ */
 
+       {
+               tchar *igcase = tgetenv(T("WIMLIB_IMAGEX_IGNORE_CASE"));
+               if (igcase != NULL) {
+                       if (!tstrcmp(igcase, T("no")) ||
+                           !tstrcmp(igcase, T("0")))
+                               init_flags |= WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE;
+                       else if (!tstrcmp(igcase, T("yes")) ||
+                                !tstrcmp(igcase, T("1")))
+                               init_flags |= WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE;
+                       else {
+                               fprintf(stderr,
+                                       "WARNING: Ignoring unknown setting of "
+                                       "WIMLIB_IMAGEX_IGNORE_CASE\n");
+                       }
+               }
+       }
+
        /* Allow being invoked as wimCOMMAND (e.g. wimapply).  */
        cmd = CMD_NONE;
        if (!tstrncmp(invocation_name, T("wim"), 3) &&