#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"
const struct wim_inode *inode = targets[i].inode;
const struct wim_dentry *dentry;
- list_for_each_entry(dentry,
- &inode->i_extraction_aliases,
- d_extraction_alias_node)
- {
+ inode_for_each_extraction_alias(dentry, inode) {
progress->extract.completed_bytes += size;
if (ctx->cur_blob_offset == ctx->cur_blob->size)
progress->extract.completed_streams++;
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))) {
return call_consume_chunk(chunk, size, ctx->saved_cbs);
}
+/* Copy the blob's data from the temporary file to each of its targets.
+ *
+ * This is executed only in the very uncommon case that a blob is being
+ * extracted to more than MAX_OPEN_FILES targets! */
static int
-extract_from_tmpfile(const tchar *tmpfile_name, struct apply_ctx *ctx)
+extract_from_tmpfile(const tchar *tmpfile_name,
+ const struct blob_descriptor *orig_blob,
+ const struct read_blob_callbacks *cbs)
{
struct blob_descriptor tmpfile_blob;
- struct blob_descriptor *orig_blob = ctx->cur_blob;
- const struct read_blob_callbacks *cbs = ctx->saved_cbs;
+ const struct blob_extraction_target *targets = blob_extraction_targets(orig_blob);
int ret;
- const u32 orig_refcnt = orig_blob->out_refcnt;
-
- BUILD_BUG_ON(MAX_OPEN_FILES <
- ARRAY_LEN(orig_blob->inline_blob_extraction_targets));
-
- struct blob_extraction_target *targets = orig_blob->blob_extraction_targets;
-
- /* Copy the blob's data from the temporary file to each of its targets.
- *
- * This is executed only in the very uncommon case that a blob is being
- * extracted to more than MAX_OPEN_FILES targets! */
memcpy(&tmpfile_blob, orig_blob, sizeof(struct blob_descriptor));
tmpfile_blob.blob_location = BLOB_IN_FILE_ON_DISK;
- tmpfile_blob.file_on_disk = ctx->tmpfile_name;
- ret = 0;
- for (u32 i = 0; i < orig_refcnt; i++) {
-
- /* Note: it usually doesn't matter whether we pass the original
- * blob descriptor to callbacks provided by the extraction
- * backend as opposed to the tmpfile blob descriptor, since they
- * shouldn't actually read data from the blob other than through
- * the read_blob_with_cbs() call below. But for
- * WIMLIB_EXTRACT_FLAG_WIMBOOT mode on Windows it does matter
- * because it needs access to the original WIM resource
- * descriptor in order to create the external backing reference.
- */
-
- orig_blob->out_refcnt = 1;
- orig_blob->inline_blob_extraction_targets[0] = targets[i];
-
- ret = call_begin_blob(orig_blob, cbs);
- if (ret)
- break;
-
- struct read_blob_callbacks wrapper_cbs = {
- .consume_chunk = cbs->consume_chunk,
- .ctx = cbs->ctx,
- };
- ret = read_blob_with_cbs(&tmpfile_blob, &wrapper_cbs);
+ tmpfile_blob.file_on_disk = (tchar *)tmpfile_name;
+ tmpfile_blob.out_refcnt = 1;
- ret = call_end_blob(orig_blob, ret, cbs);
+ for (u32 i = 0; i < orig_blob->out_refcnt; i++) {
+ tmpfile_blob.inline_blob_extraction_targets[0] = targets[i];
+ ret = read_blob_with_cbs(&tmpfile_blob, cbs);
if (ret)
- break;
+ return ret;
}
- FREE(targets);
- orig_blob->out_refcnt = 0;
- return ret;
+ return 0;
}
static int
if (unlikely(filedes_valid(&ctx->tmpfile_fd))) {
filedes_close(&ctx->tmpfile_fd);
if (!status)
- status = extract_from_tmpfile(ctx->tmpfile_name, ctx);
+ status = extract_from_tmpfile(ctx->tmpfile_name, blob,
+ ctx->saved_cbs);
filedes_invalidate(&ctx->tmpfile_fd);
tunlink(ctx->tmpfile_name);
FREE(ctx->tmpfile_name);
{
size_t i, j = 0;
for (i = 0; i < num_trees; i++) {
- if (!trees[i]->tmp_flag) {
+ if (!trees[i]->d_tmp_flag) {
/* Found distinct dentry. */
- trees[i]->tmp_flag = 1;
+ trees[i]->d_tmp_flag = 1;
trees[j++] = trees[i];
}
}
for (i = 0; i < j; i++)
- trees[i]->tmp_flag = 0;
+ trees[i]->d_tmp_flag = 0;
return j;
}
{
size_t i, j = 0;
for (i = 0; i < num_trees; i++)
- trees[i]->tmp_flag = 1;
+ trees[i]->d_tmp_flag = 1;
for (i = 0; i < num_trees; i++) {
struct wim_dentry *d = trees[i];
while (!dentry_is_root(d)) {
d = d->d_parent;
- if (d->tmp_flag)
+ if (d->d_tmp_flag)
goto tree_contained;
}
trees[j++] = trees[i];
continue;
tree_contained:
- trees[i]->tmp_flag = 0;
+ trees[i]->d_tmp_flag = 0;
}
for (i = 0; i < j; i++)
- trees[i]->tmp_flag = 0;
+ trees[i]->d_tmp_flag = 0;
return j;
}
static int
dentry_delete_from_list(struct wim_dentry *dentry, void *_ignore)
{
- list_del(&dentry->d_extraction_list_node);
- dentry_reset_extraction_list_node(dentry);
+ if (will_extract_dentry(dentry)) {
+ list_del(&dentry->d_extraction_list_node);
+ dentry_reset_extraction_list_node(dentry);
+ }
return 0;
}
dentry_reset_extraction_list_node(dentry);
inode->i_visited = 0;
inode->i_can_externally_back = 0;
- if ((void *)dentry->d_extraction_name != (void *)dentry->file_name)
+ if ((void *)dentry->d_extraction_name != (void *)dentry->d_name)
FREE(dentry->d_extraction_name);
dentry->d_extraction_name = NULL;
dentry->d_extraction_name_nchars = 0;
#ifdef WITH_NTFS_3G
if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_NTFS) {
- dentry->d_extraction_name = dentry->file_name;
- dentry->d_extraction_name_nchars = dentry->file_name_nbytes /
+ dentry->d_extraction_name = dentry->d_name;
+ dentry->d_extraction_name_nchars = dentry->d_name_nbytes /
sizeof(utf16lechar);
return 0;
}
}
}
- if (file_name_valid(dentry->file_name, dentry->file_name_nbytes / 2, false)) {
- ret = utf16le_get_tstr(dentry->file_name,
- dentry->file_name_nbytes,
+ if (file_name_valid(dentry->d_name, dentry->d_name_nbytes / 2, false)) {
+ size_t nbytes = 0;
+ ret = utf16le_get_tstr(dentry->d_name,
+ dentry->d_name_nbytes,
(const tchar **)&dentry->d_extraction_name,
- &dentry->d_extraction_name_nchars);
- dentry->d_extraction_name_nchars /= sizeof(tchar);
+ &nbytes);
+ dentry->d_extraction_name_nchars = nbytes / sizeof(tchar);
return ret;
} else {
if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES)
out_replace:
{
- utf16lechar utf16_name_copy[dentry->file_name_nbytes / 2];
+ utf16lechar utf16_name_copy[dentry->d_name_nbytes / 2];
- memcpy(utf16_name_copy, dentry->file_name, dentry->file_name_nbytes);
- file_name_valid(utf16_name_copy, dentry->file_name_nbytes / 2, true);
+ memcpy(utf16_name_copy, dentry->d_name, dentry->d_name_nbytes);
+ file_name_valid(utf16_name_copy, dentry->d_name_nbytes / 2, true);
const tchar *tchar_name;
size_t tchar_nchars;
ret = utf16le_get_tstr(utf16_name_copy,
- dentry->file_name_nbytes,
+ dentry->d_name_nbytes,
&tchar_name, &tchar_nchars);
if (ret)
return ret;
dentry_list_build_inode_alias_lists(struct list_head *dentry_list)
{
struct wim_dentry *dentry;
- struct wim_inode *inode;
+
+ list_for_each_entry(dentry, dentry_list, d_extraction_list_node)
+ dentry->d_inode->i_first_extraction_alias = NULL;
list_for_each_entry(dentry, dentry_list, d_extraction_list_node) {
- inode = dentry->d_inode;
- if (!inode->i_visited)
- INIT_LIST_HEAD(&inode->i_extraction_aliases);
- list_add_tail(&dentry->d_extraction_alias_node,
- &inode->i_extraction_aliases);
- inode->i_visited = 1;
+ dentry->d_next_extraction_alias = dentry->d_inode->i_first_extraction_alias;
+ dentry->d_inode->i_first_extraction_alias = dentry;
}
- list_for_each_entry(dentry, dentry_list, d_extraction_list_node)
- dentry->d_inode->i_visited = 0;
}
static void
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;
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,
.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;