X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fextract.c;h=e80bbe94a4d2e65f0b23cc0b8ce4ee96c94d53fb;hp=625224b34924d4eae6068f15b891402261cdf323;hb=8b709192cd2811b83c248fbe61ca4f11ee9de797;hpb=d820468f3c760006bbab61771ba608deb727c53f diff --git a/src/extract.c b/src/extract.c index 625224b3..e80bbe94 100644 --- a/src/extract.c +++ b/src/extract.c @@ -54,11 +54,11 @@ #include "wimlib/metadata.h" #include "wimlib/pathlist.h" #include "wimlib/paths.h" +#include "wimlib/pattern.h" #include "wimlib/reparse.h" #include "wimlib/resource.h" #include "wimlib/security.h" #include "wimlib/unix_data.h" -#include "wimlib/wildcard.h" #include "wimlib/wim.h" #include "wimlib/win32.h" /* for realpath() equivalent */ #include "wimlib/xml.h" @@ -84,7 +84,12 @@ WIMLIB_EXTRACT_FLAG_STRICT_GLOB | \ WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES | \ WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE | \ - WIMLIB_EXTRACT_FLAG_WIMBOOT) + WIMLIB_EXTRACT_FLAG_WIMBOOT | \ + WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K | \ + WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K | \ + WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K | \ + WIMLIB_EXTRACT_FLAG_COMPACT_LZX \ + ) /* Send WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE or * WIMLIB_PROGRESS_MSG_EXTRACT_METADATA. */ @@ -341,30 +346,9 @@ extract_chunk_wrapper(const void *chunk, size_t size, void *_ctx) if (ret) return ret; - if (progress->extract.completed_bytes >= - progress->extract.total_bytes) - { - ctx->next_progress = UINT64_MAX; - } else { - /* Send new message as soon as another 1/128 of the - * total has been extracted. (Arbitrary number.) */ - ctx->next_progress = - progress->extract.completed_bytes + - progress->extract.total_bytes / 128; - - /* ... Unless that would be more than 5000000 bytes, in - * which case send the next after the next 5000000 - * bytes. (Another arbitrary number.) */ - if (progress->extract.completed_bytes + 5000000 < - ctx->next_progress) - ctx->next_progress = - progress->extract.completed_bytes + 5000000; - - /* ... But always send a message as soon as we're - * completely done. */ - if (progress->extract.total_bytes < ctx->next_progress) - ctx->next_progress = progress->extract.total_bytes; - } + set_next_progress(progress->extract.completed_bytes, + progress->extract.total_bytes, + &ctx->next_progress); } if (unlikely(filedes_valid(&ctx->tmpfile_fd))) { @@ -676,19 +660,20 @@ file_name_valid(utf16lechar *name, size_t num_chars, bool fix) if (num_chars == 0) return true; for (i = 0; i < num_chars; i++) { - switch (name[i]) { + switch (le16_to_cpu(name[i])) { #ifdef __WIN32__ - case cpu_to_le16('\\'): - case cpu_to_le16(':'): - case cpu_to_le16('*'): - case cpu_to_le16('?'): - case cpu_to_le16('"'): - case cpu_to_le16('<'): - case cpu_to_le16('>'): - case cpu_to_le16('|'): + case '\x01'...'\x1F': + case '\\': + case ':': + case '*': + case '?': + case '"': + case '<': + case '>': + case '|': #endif - case cpu_to_le16('/'): - case cpu_to_le16('\0'): + case '/': + case '\0': if (fix) name[i] = replacement_char; else @@ -696,16 +681,6 @@ file_name_valid(utf16lechar *name, size_t num_chars, bool fix) } } -#ifdef __WIN32__ - if (name[num_chars - 1] == cpu_to_le16(' ') || - name[num_chars - 1] == cpu_to_le16('.')) - { - if (fix) - name[num_chars - 1] = replacement_char; - else - return false; - } -#endif return true; } @@ -1003,10 +978,11 @@ ref_stream_if_needed(struct wim_dentry *dentry, struct wim_inode *inode, * - file is a directory * - file is encrypted * - backend needs to create the file as UNIX symlink - * - backend will extract the stream as externally backed + * - backend will extract the stream as externally + * backed from the WIM archive itself */ - if (ctx->apply_ops->will_externally_back) { - int ret = (*ctx->apply_ops->will_externally_back)(dentry, ctx); + if (ctx->apply_ops->will_back_from_wim) { + int ret = (*ctx->apply_ops->will_back_from_wim)(dentry, ctx); if (ret > 0) /* Error? */ return ret; if (ret < 0) /* Won't externally back? */ @@ -1509,6 +1485,34 @@ check_extract_flags(const WIMStruct *wim, int *extract_flags_p) #endif } + if (extract_flags & (WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K | + WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K | + WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K | + WIMLIB_EXTRACT_FLAG_COMPACT_LZX)) + { + #ifdef __WIN32__ + int count = 0; + count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K) != 0); + count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K) != 0); + count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K) != 0); + count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_LZX) != 0); + if (count != 1) { + ERROR("Only one compression format can be specified " + "for compact-mode extraction!"); + return WIMLIB_ERR_INVALID_PARAM; + } + if (extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT) { + ERROR("Compact-mode extraction and WIMBoot-mode " + "extraction are mutually exclusive!"); + return WIMLIB_ERR_INVALID_PARAM; + } + #else + ERROR("Compact-mode extraction (System Compression) " + "is only supported on Windows!"); + return WIMLIB_ERR_UNSUPPORTED; + #endif + } + if ((extract_flags & (WIMLIB_EXTRACT_FLAG_RPFIX | WIMLIB_EXTRACT_FLAG_NORPFIX | @@ -1525,22 +1529,6 @@ check_extract_flags(const WIMStruct *wim, int *extract_flags_p) return 0; } -static u32 -get_wildcard_flags(int extract_flags) -{ - u32 wildcard_flags = 0; - - if (extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_GLOB) - wildcard_flags |= WILDCARD_FLAG_ERROR_IF_NO_MATCH; - else - wildcard_flags |= WILDCARD_FLAG_WARN_IF_NO_MATCH; - - if (default_ignore_case) - wildcard_flags |= WILDCARD_FLAG_CASE_INSENSITIVE; - - return wildcard_flags; -} - struct append_dentry_ctx { struct wim_dentry **dentries; size_t num_dentries; @@ -1569,6 +1557,31 @@ append_dentry_cb(struct wim_dentry *dentry, void *_ctx) return 0; } +/* Append dentries matched by a path which can contain wildcard characters. */ +static int +append_matched_dentries(WIMStruct *wim, const tchar *orig_pattern, + int extract_flags, struct append_dentry_ctx *ctx) +{ + const size_t count_before = ctx->num_dentries; + tchar *pattern; + int ret; + + pattern = canonicalize_wim_path(orig_pattern); + if (!pattern) + return WIMLIB_ERR_NOMEM; + ret = expand_path_pattern(wim_get_current_root_dentry(wim), pattern, + append_dentry_cb, ctx); + FREE(pattern); + if (ret || ctx->num_dentries > count_before) + return ret; + if (extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_GLOB) { + ERROR("No matches for path pattern \"%"TS"\"", orig_pattern); + return WIMLIB_ERR_PATH_DOES_NOT_EXIST; + } + WARNING("No matches for path pattern \"%"TS"\"", orig_pattern); + return 0; +} + static int do_wimlib_extract_paths(WIMStruct *wim, int image, const tchar *target, const tchar * const *paths, size_t num_paths, @@ -1611,20 +1624,10 @@ do_wimlib_extract_paths(WIMStruct *wim, int image, const tchar *target, .num_alloc_dentries = 0, }; - u32 wildcard_flags = get_wildcard_flags(extract_flags); - for (size_t i = 0; i < num_paths; i++) { - tchar *path = canonicalize_wim_path(paths[i]); - if (path == NULL) { - ret = WIMLIB_ERR_NOMEM; - trees = append_dentry_ctx.dentries; - goto out_free_trees; - } - ret = expand_wildcard(wim, path, - append_dentry_cb, - &append_dentry_ctx, - wildcard_flags); - FREE(path); + ret = append_matched_dentries(wim, paths[i], + extract_flags, + &append_dentry_ctx); if (ret) { trees = append_dentry_ctx.dentries; goto out_free_trees;