X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=programs%2Fimagex.c;h=1a3cbbd5a05176975e22ea78764d7b8e43bdbeb6;hp=9ee6df34ed630e99198f13584456f2f2c823d74a;hb=f69ae15310f292995d2f0838c91ee61b721c356c;hpb=d55cda59032e0abe5f71cd6f16ade943d2713fee diff --git a/programs/imagex.c b/programs/imagex.c index 9ee6df34..1a3cbbd5 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -104,7 +104,7 @@ IMAGEX_PROGNAME" apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all]\n" " (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n" " [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n" " [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n" -" [--force-all-files]\n" +" [--include-invalid-names]\n" ), [CAPTURE] = T( @@ -135,7 +135,7 @@ T( IMAGEX_PROGNAME" extract WIMFILE (IMAGE_NUM | IMAGE_NAME) [PATH...]\n" " [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data]\n" " [--no-acls] [--strict-acls] [--to-stdout] [--dest-dir=DIR]\n" -" [--force-all-files]\n" +" [--include-invalid-names]\n" ), [INFO] = T( @@ -176,7 +176,7 @@ IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild] [--lazy]\n" T( IMAGEX_PROGNAME" update WIMFILE [IMAGE_NUM | IMAGE_NAME] [--check] [--rebuild]\n" " [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n" -" [DEFAULT_DELETE_OPTIONS] < CMDFILE\n" +" [DEFAULT_DELETE_OPTIONS] [--command=STRING] [< CMDFILE]\n" ), }; @@ -199,6 +199,7 @@ enum { IMAGEX_ALLOW_OTHER_OPTION, IMAGEX_BOOT_OPTION, IMAGEX_CHECK_OPTION, + IMAGEX_COMMAND_OPTION, IMAGEX_COMMIT_OPTION, IMAGEX_COMPRESS_OPTION, IMAGEX_CONFIG_OPTION, @@ -208,9 +209,9 @@ enum { IMAGEX_EXTRACT_XML_OPTION, IMAGEX_FLAGS_OPTION, IMAGEX_FORCE_OPTION, - IMAGEX_FORCE_ALL_FILES_OPTION, IMAGEX_HARDLINK_OPTION, IMAGEX_HEADER_OPTION, + IMAGEX_INCLUDE_INVALID_NAMES_OPTION, IMAGEX_LAZY_OPTION, IMAGEX_LOOKUP_TABLE_OPTION, IMAGEX_METADATA_OPTION, @@ -246,7 +247,7 @@ static const struct option apply_options[] = { {T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION}, {T("rpfix"), no_argument, NULL, IMAGEX_RPFIX_OPTION}, {T("norpfix"), no_argument, NULL, IMAGEX_NORPFIX_OPTION}, - {T("force-all-files"), no_argument, NULL, IMAGEX_FORCE_ALL_FILES_OPTION}, + {T("include-invalid-names"), no_argument, NULL, IMAGEX_INCLUDE_INVALID_NAMES_OPTION}, {NULL, 0, NULL, 0}, }; static const struct option capture_or_append_options[] = { @@ -294,7 +295,7 @@ static const struct option extract_options[] = { {T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION}, {T("dest-dir"), required_argument, NULL, IMAGEX_DEST_DIR_OPTION}, {T("to-stdout"), no_argument, NULL, IMAGEX_TO_STDOUT_OPTION}, - {T("force-all-files"), no_argument, NULL, IMAGEX_FORCE_ALL_FILES_OPTION}, + {T("include-invalid-names"), no_argument, NULL, IMAGEX_INCLUDE_INVALID_NAMES_OPTION}, {NULL, 0, NULL, 0}, }; @@ -353,6 +354,7 @@ static const struct option update_options[] = { {T("threads"), required_argument, NULL, IMAGEX_THREADS_OPTION}, {T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION}, {T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION}, + {T("command"), required_argument, NULL, IMAGEX_COMMAND_OPTION}, /* Default delete options */ {T("force"), no_argument, NULL, IMAGEX_FORCE_OPTION}, @@ -368,6 +370,7 @@ static const struct option update_options[] = { {T("noacls"), no_argument, NULL, IMAGEX_NO_ACLS_OPTION}, {T("no-acls"), no_argument, NULL, IMAGEX_NO_ACLS_OPTION}, {T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION}, + {NULL, 0, NULL, 0}, }; @@ -1080,8 +1083,8 @@ imagex_progress_func(enum wimlib_progress_msg msg, unit_shift = get_unit(info->integrity.total_bytes, &unit_name); percent_done = TO_PERCENT(info->integrity.completed_bytes, info->integrity.total_bytes); - tprintf(T("\rVerifying integrity of \"%"TS"\": %"PRIu64" "TS" " - "of %"PRIu64" "TS" (%u%%) done"), + tprintf(T("\rVerifying integrity of \"%"TS"\": %"PRIu64" %"TS" " + "of %"PRIu64" %"TS" (%u%%) done"), info->integrity.filename, info->integrity.completed_bytes >> unit_shift, unit_name, @@ -1533,7 +1536,7 @@ imagex_apply(int argc, tchar **argv) case IMAGEX_RPFIX_OPTION: extract_flags |= WIMLIB_EXTRACT_FLAG_RPFIX; break; - case IMAGEX_FORCE_ALL_FILES_OPTION: + case IMAGEX_INCLUDE_INVALID_NAMES_OPTION: extract_flags |= WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES; extract_flags |= WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS; break; @@ -1656,6 +1659,7 @@ imagex_capture_or_append(int argc, tchar **argv) bool capture_sources_malloced; struct wimlib_capture_source *capture_sources; size_t num_sources; + bool name_defaulted; for_opt(c, capture_or_append_options) { switch (c) { @@ -1727,13 +1731,16 @@ imagex_capture_or_append(int argc, tchar **argv) if (argc >= 3) { name = argv[2]; + name_defaulted = false; } else { /* Set default name to SOURCE argument, omitting any directory * prefixes and trailing slashes. This requires making a copy - * of @source. */ + * of @source. Leave some free characters at the end in case we + * append a number to keep the name unique. */ source_name_len = tstrlen(source); - source_copy = alloca((source_name_len + 1) * sizeof(tchar)); + source_copy = alloca((source_name_len + 1 + 25) * sizeof(tchar)); name = tbasename(tstrcpy(source_copy, source)); + name_defaulted = true; } /* Image description defaults to NULL if not given. */ desc = (argc >= 4) ? argv[3] : NULL; @@ -1812,6 +1819,20 @@ imagex_capture_or_append(int argc, tchar **argv) } } } + + if (cmd == APPEND && name_defaulted) { + /* If the user did not specify an image name, and the basename + * of the source already exists as an image name in the WIM + * file, append a suffix to make it unique. */ + unsigned long conflict_idx; + tchar *name_end = tstrchr(name, T('\0')); + for (conflict_idx = 1; + wimlib_image_name_in_use(w, name); + conflict_idx++) + { + tsprintf(name_end, T(" (%lu)"), conflict_idx); + } + } #ifdef __WIN32__ win32_acquire_capture_privileges(); #endif @@ -2268,7 +2289,7 @@ imagex_extract(int argc, tchar **argv) extract_flags |= WIMLIB_EXTRACT_FLAG_TO_STDOUT; imagex_be_quiet = true; break; - case IMAGEX_FORCE_ALL_FILES_OPTION: + case IMAGEX_INCLUDE_INVALID_NAMES_OPTION: extract_flags |= WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES; extract_flags |= WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS; break; @@ -2985,11 +3006,12 @@ imagex_update(int argc, tchar **argv) int default_delete_flags = 0; unsigned num_threads = 0; int c; - tchar *cmd_file_contents; + tchar *cmd_file_contents = NULL; size_t cmd_file_nchars; struct wimlib_update_command *cmds; size_t num_cmds; int num_images; + tchar *command_str = NULL; const tchar *config_file = NULL; tchar *config_str; @@ -3012,7 +3034,22 @@ imagex_update(int argc, tchar **argv) case IMAGEX_REBUILD_OPTION: write_flags |= WIMLIB_WRITE_FLAG_REBUILD; break; - + case IMAGEX_COMMAND_OPTION: + if (command_str) { + imagex_error(T("--command may only be specified " + "one time. Please provide\n" + " the update commands " + "on standard input instead.")); + ret = -1; + goto out; + } + command_str = tstrdup(optarg); + if (!command_str) { + imagex_error(T("Out of memory!")); + ret = -1; + goto out; + } + break; /* Default delete options */ case IMAGEX_FORCE_OPTION: default_delete_flags |= WIMLIB_DELETE_FLAG_FORCE; @@ -3100,20 +3137,26 @@ imagex_update(int argc, tchar **argv) config = &default_capture_config; } - /* Read update commands from standard input */ - if (isatty(STDIN_FILENO)) { - tputs(T("Reading update commands from standard input...")); - recommend_man_page(T("update")); - } - cmd_file_contents = stdin_get_text_contents(&cmd_file_nchars); - if (!cmd_file_contents) { - ret = -1; - goto out_free_config; - } + /* Read update commands from standard input, or the command string if + * specified. */ + if (command_str) { + cmds = parse_update_command_file(&command_str, tstrlen(command_str), + &num_cmds); + } else { + if (isatty(STDIN_FILENO)) { + tputs(T("Reading update commands from standard input...")); + recommend_man_page(T("update")); + } + cmd_file_contents = stdin_get_text_contents(&cmd_file_nchars); + if (!cmd_file_contents) { + ret = -1; + goto out_free_config; + } - /* Parse the update commands */ - cmds = parse_update_command_file(&cmd_file_contents, cmd_file_nchars, - &num_cmds); + /* Parse the update commands */ + cmds = parse_update_command_file(&cmd_file_contents, cmd_file_nchars, + &num_cmds); + } if (!cmds) { ret = -1; goto out_free_cmd_file_contents; @@ -3151,7 +3194,6 @@ out_release_privs: #ifdef __WIN32__ win32_release_capture_privileges(); #endif -out_free_cmds: free(cmds); out_free_cmd_file_contents: free(cmd_file_contents); @@ -3164,6 +3206,7 @@ out_free_config: out_wimlib_free: wimlib_free(wim); out: + free(command_str); return ret; out_usage: usage(UPDATE);