X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fextract_image.c;fp=src%2Fextract_image.c;h=f6bca157a2f7e14da273daf222e33dae9be1037c;hb=e5c13f94058aedcea95236a9728093fa283d49b3;hp=69a4b9e8d0fac4298f376197f69b88c3d4ecf40b;hpb=fb964811a120ad28cac62a9a3343def5bf474f03;p=wimlib diff --git a/src/extract_image.c b/src/extract_image.c index 69a4b9e8..f6bca157 100644 --- a/src/extract_image.c +++ b/src/extract_image.c @@ -863,6 +863,33 @@ sort_stream_list_by_wim_position(struct list_head *stream_list) 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. @@ -951,6 +978,11 @@ extract_tree(WIMStruct *wim, const tchar *wim_source_path, const tchar *target, } 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, @@ -960,6 +992,11 @@ extract_tree(WIMStruct *wim, const tchar *wim_source_path, const tchar *target, 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, @@ -982,10 +1019,6 @@ extract_tree(WIMStruct *wim, const tchar *wim_source_path, const tchar *target, &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;