]> wimlib.net Git - wimlib/blobdiff - src/extract.c
Improve write streams performance and handling of joins
[wimlib] / src / extract.c
index 95071bd7bfbb35b45dec106755a88b1c0db204e8..d9e03333e43403f701f337535253d0d4e403aafc 100644 (file)
@@ -1203,8 +1203,7 @@ extract_stream_list(struct apply_ctx *ctx)
        bool can_seek;
        int ret;
 
-       can_seek = !(lseek(ctx->wim->in_fd.fd, 0, SEEK_CUR) == (off_t)-1 &&
-                    errno == ESPIPE);
+       can_seek = (lseek(ctx->wim->in_fd.fd, 0, SEEK_CUR) != -1);
        list_for_each_entry(lte, &ctx->stream_list, extraction_list) {
                ret = extract_stream_instances(lte, ctx, can_seek);
                if (ret)
@@ -1338,42 +1337,6 @@ dentry_extract_final(struct wim_dentry *dentry, void *_ctx)
        return extract_timestamps(path, ctx, dentry);
 }
 
-/* Sorts a list of streams in ascending order of their offset in the WIM file in
- * order to prepare for sequential extraction.  */
-static int
-sort_stream_list_by_wim_position(struct list_head *stream_list)
-{
-       struct list_head *cur;
-       size_t num_streams;
-       struct wim_lookup_table_entry **array;
-       size_t i;
-       size_t array_size;
-
-       num_streams = 0;
-       list_for_each(cur, stream_list)
-               num_streams++;
-       array_size = num_streams * sizeof(array[0]);
-       array = MALLOC(array_size);
-       if (!array) {
-               ERROR("Failed to allocate %zu bytes to sort stream entries",
-                     array_size);
-               return WIMLIB_ERR_NOMEM;
-       }
-       cur = stream_list->next;
-       for (i = 0; i < num_streams; i++) {
-               array[i] = container_of(cur, struct wim_lookup_table_entry, extraction_list);
-               cur = cur->next;
-       }
-
-       qsort(array, num_streams, sizeof(array[0]), cmp_streams_by_wim_position);
-
-       INIT_LIST_HEAD(stream_list);
-       for (i = 0; i < num_streams; i++)
-               list_add_tail(&array[i]->extraction_list, stream_list);
-       FREE(array);
-       return 0;
-}
-
 /*
  * Extract a WIM dentry to standard output.
  *
@@ -2022,8 +1985,7 @@ extract_tree(WIMStruct *wim, const tchar *wim_source_path, const tchar *target,
         * output.  In that case, "root" should be a single file, not a
         * directory tree.  (If not, extract_dentry_to_stdout() will
         * return an error.)  */
-       if (extract_flags & WIMLIB_EXTRACT_FLAG_TO_STDOUT &&
-           !(extract_flags & WIMLIB_EXTRACT_FLAG_FROM_PIPE)) {
+       if (extract_flags & WIMLIB_EXTRACT_FLAG_TO_STDOUT) {
                ret = extract_dentry_to_stdout(root);
                goto out_teardown_stream_list;
        }
@@ -2035,7 +1997,10 @@ extract_tree(WIMStruct *wim, const tchar *wim_source_path, const tchar *target,
                              WIMLIB_EXTRACT_FLAG_FROM_PIPE))
                                        == WIMLIB_EXTRACT_FLAG_SEQUENTIAL)
        {
-               ret = sort_stream_list_by_wim_position(&ctx.stream_list);
+               ret = sort_stream_list_by_sequential_order(
+                               &ctx.stream_list,
+                               offsetof(struct wim_lookup_table_entry,
+                                        extraction_list));
                if (ret)
                        goto out_teardown_stream_list;
        }
@@ -2276,8 +2241,7 @@ do_wimlib_extract_files(WIMStruct *wim,
                return ret;
 
        /* Make sure there are no streams in the WIM that have not been
-        * checksummed yet.  Needed at least because 'unhashed_list' aliases
-        * 'extraction_list' in `struct wim_lookup_table_entry'.  */
+        * checksummed yet.  */
        ret = wim_checksum_unhashed_streams(wim);
        if (ret)
                return ret;
@@ -2461,12 +2425,10 @@ extract_all_images(WIMStruct *wim,
 
        extract_flags |= WIMLIB_EXTRACT_FLAG_MULTI_IMAGE;
 
-#ifdef WITH_NTFS_3G
        if (extract_flags & WIMLIB_EXTRACT_FLAG_NTFS) {
                ERROR("Cannot extract multiple images in NTFS extraction mode.");
                return WIMLIB_ERR_INVALID_PARAM;
        }
-#endif
 
        if (tstat(target, &stbuf)) {
                if (errno == ENOENT) {
@@ -2629,16 +2591,26 @@ wimlib_extract_image_from_pipe(int pipe_fd, const tchar *image_num_or_name,
 
        /* Get image index (this may use the XML data that was just read to
         * resolve an image name).  */
-       image = wimlib_resolve_image(pwm, image_num_or_name);
-       if (image == WIMLIB_NO_IMAGE) {
-               ERROR("\"%"TS"\" is not a valid image in the pipable WIM!",
-                     image_num_or_name);
-               ret = WIMLIB_ERR_INVALID_IMAGE;
-               goto out_wimlib_free;
-       } else if (image == WIMLIB_ALL_IMAGES) {
-               ERROR("Applying all images from a pipe is not supported.");
-               ret = WIMLIB_ERR_INVALID_IMAGE;
-               goto out_wimlib_free;
+       if (image_num_or_name) {
+               image = wimlib_resolve_image(pwm, image_num_or_name);
+               if (image == WIMLIB_NO_IMAGE) {
+                       ERROR("\"%"TS"\" is not a valid image in the pipable WIM!",
+                             image_num_or_name);
+                       ret = WIMLIB_ERR_INVALID_IMAGE;
+                       goto out_wimlib_free;
+               } else if (image == WIMLIB_ALL_IMAGES) {
+                       ERROR("Applying all images from a pipe is not supported.");
+                       ret = WIMLIB_ERR_INVALID_IMAGE;
+                       goto out_wimlib_free;
+               }
+       } else {
+               if (pwm->hdr.image_count != 1) {
+                       ERROR("No image was specified, but the pipable WIM "
+                             "did not contain exactly 1 image");
+                       ret = WIMLIB_ERR_INVALID_IMAGE;
+                       goto out_wimlib_free;
+               }
+               image = 1;
        }
 
        /* Load the needed metadata resource.  */