static int
fd_apply_unix_data(int fd, const char *path,
- const struct wimlib_unix_data *unix_data)
+ const struct wimlib_unix_data *unix_data,
+ int extract_flags)
{
+ if (extract_flags & WIMLIB_EXTRACT_FLAG_NO_ACLS)
+ return 0;
+
if (fchown(fd, unix_data->uid, unix_data->gid)) {
- if (errno == EPERM) {
+ if (errno == EPERM &&
+ !(extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_ACLS))
+ {
WARNING_WITH_ERRNO("failed to set file UNIX "
"owner/group on \"%s\"", path);
- /* Ignore? */
} else {
ERROR_WITH_ERRNO("failed to set file UNIX "
"owner/group on \"%s\"", path);
- return WIMLIB_ERR_INVALID_DENTRY;
+ return (errno == EPERM) ? WIMLIB_ERR_INSUFFICIENT_PRIVILEGES_TO_EXTRACT :
+ WIMLIB_ERR_WRITE;
}
}
if (fchmod(fd, unix_data->mode)) {
- if (errno == EPERM) {
+ if (errno == EPERM &&
+ !(extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_ACLS))
+ {
WARNING_WITH_ERRNO("failed to set UNIX file mode "
"on \"%s\"", path);
- /* Ignore? */
} else {
ERROR_WITH_ERRNO("failed to set UNIX file mode "
"on \"%s\"", path);
- return WIMLIB_ERR_INVALID_DENTRY;
+ return (errno == EPERM) ? WIMLIB_ERR_INSUFFICIENT_PRIVILEGES_TO_EXTRACT :
+ WIMLIB_ERR_WRITE;
}
}
return 0;
}
static int
-dir_apply_unix_data(const char *dir, const struct wimlib_unix_data *unix_data)
+dir_apply_unix_data(const char *dir, const struct wimlib_unix_data *unix_data,
+ int extract_flags)
{
int dfd = open(dir, O_RDONLY);
int ret;
if (dfd >= 0) {
- ret = fd_apply_unix_data(dfd, dir, unix_data);
- if (close(dfd)) {
+ ret = fd_apply_unix_data(dfd, dir, unix_data, extract_flags);
+ if (close(dfd) && ret == 0) {
ERROR_WITH_ERRNO("can't close directory `%s'", dir);
- ret = WIMLIB_ERR_MKDIR;
+ ret = WIMLIB_ERR_WRITE;
}
} else {
ERROR_WITH_ERRNO("can't open directory `%s'", dir);
- ret = WIMLIB_ERR_MKDIR;
+ ret = WIMLIB_ERR_OPENDIR;
}
return ret;
}
else if (ret < 0)
ret = 0;
else
- ret = fd_apply_unix_data(out_fd, output_path, &unix_data);
+ ret = fd_apply_unix_data(out_fd, output_path, &unix_data,
+ args->extract_flags);
if (ret)
goto out;
}
static int
extract_directory(struct wim_dentry *dentry,
- const tchar *output_path, bool is_root)
+ const tchar *output_path, bool is_root,
+ int extract_flags)
{
int ret;
struct stat stbuf;
dir_exists:
ret = 0;
#ifndef __WIN32__
- if (dentry) {
+ if (extract_flags & WIMLIB_EXTRACT_FLAG_UNIX_DATA) {
struct wimlib_unix_data unix_data;
ret = inode_get_unix_data(dentry->d_inode, &unix_data, NULL);
if (ret > 0)
else if (ret < 0)
ret = 0;
else
- ret = dir_apply_unix_data(output_path, &unix_data);
+ ret = dir_apply_unix_data(output_path, &unix_data,
+ extract_flags);
}
#endif
return ret;
else if (inode_is_directory(inode))
return extract_directory((args->extract_flags &
WIMLIB_EXTRACT_FLAG_UNIX_DATA) ? dentry : NULL,
- output_path, false);
+ output_path, false, args->extract_flags);
else
return extract_regular_file(dentry, args, output_path);
}
return 0;
}
+/*
+ * Extract a dentry to standard output.
+ *
+ * This obviously doesn't make sense in all cases. We return an error if the
+ * dentry does not correspond to a regular file. Otherwise we extract the
+ * unnamed data stream only.
+ */
+static int
+extract_dentry_to_stdout(struct wim_dentry *dentry)
+{
+ int ret = 0;
+ if (!dentry_is_regular_file(dentry)) {
+ ERROR("\"%"TS"\" is not a regular file and therefore cannot be "
+ "extracted to standard output", dentry->_full_path);
+ ret = WIMLIB_ERR_NOT_A_REGULAR_FILE;
+ } else {
+ struct wim_lookup_table_entry *lte;
+
+ lte = inode_unnamed_lte_resolved(dentry->d_inode);
+ if (lte) {
+ ret = extract_wim_resource_to_fd(lte, STDOUT_FILENO,
+ wim_resource_size(lte));
+ }
+ }
+ return ret;
+}
+
/*
* extract_tree - Extract a file or directory tree from the currently selected
* WIM image.
}
args.extract_root = root;
+ ret = calculate_dentry_tree_full_paths(root);
+ if (ret)
+ goto out_ntfs_umount;
+
+
/* Build a list of the streams that need to be extracted */
find_streams_for_extraction(root,
&stream_list,
calculate_bytes_to_extract(&stream_list, extract_flags,
&args.progress);
+ if (extract_flags & WIMLIB_EXTRACT_FLAG_TO_STDOUT) {
+ ret = extract_dentry_to_stdout(root);
+ goto out_mark_inodes_unvisited;
+ }
+
if (progress_func) {
progress_func(*wim_source_path ? WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN :
WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN,
&args.progress);
}
- ret = calculate_dentry_tree_full_paths(root);
- if (ret)
- goto out_mark_inodes_unvisited;
-
/* Make the directory structure and extract empty files */
args.extract_flags |= WIMLIB_EXTRACT_FLAG_NO_STREAMS;
args.apply_dentry = ops->apply_dentry;
if (ret)
goto out;
+ if (num_cmds == 0)
+ goto out;
+
if (num_additional_swms) {
ret = new_joined_lookup_table(wim, additional_swms,
num_additional_swms,
int image;
const tchar *image_name;
- ret = extract_directory(NULL, target, true);
+ ret = extract_directory(NULL, target, true, 0);
if (ret)
return ret;