]> wimlib.net Git - wimlib/blobdiff - src/resource.c
Fixes
[wimlib] / src / resource.c
index 5237b88a37fd646613770df5768e3f56625cd2ab..dc5b7a806fe24d3bb61aad2bb5528ffd787e2a18 100644 (file)
@@ -593,7 +593,11 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte,
        }
        goto out_release_fp;
 read_error:
        }
        goto out_release_fp;
 read_error:
-       ERROR_WITH_ERRNO("Error reading data from WIM");
+       if (ferror(wim_fp)) {
+               ERROR_WITH_ERRNO("Error reading data from WIM");
+       } else {
+               ERROR("Unexpected EOF in WIM!");
+       }
        ret = WIMLIB_ERR_READ;
 out_release_fp:
        if (flags & WIMLIB_RESOURCE_FLAG_THREADSAFE_READ)
        ret = WIMLIB_ERR_READ;
 out_release_fp:
        if (flags & WIMLIB_RESOURCE_FLAG_THREADSAFE_READ)
@@ -838,6 +842,28 @@ extract_wim_resource_to_fd(const struct wim_lookup_table_entry *lte,
        return extract_wim_resource(lte, size, extract_wim_chunk_to_fd, &fd);
 }
 
        return extract_wim_resource(lte, size, extract_wim_chunk_to_fd, &fd);
 }
 
+
+static int
+sha1_chunk(const void *buf, size_t len, void *ctx)
+{
+       sha1_update(ctx, buf, len);
+       return 0;
+}
+
+int
+sha1_resource(struct wim_lookup_table_entry *lte)
+{
+       int ret;
+       SHA_CTX sha_ctx;
+
+       sha1_init(&sha_ctx);
+       ret = read_resource_prefix(lte, wim_resource_size(lte),
+                                  sha1_chunk, &sha_ctx, 0);
+       if (ret == 0)
+               sha1_final(lte->hash, &sha_ctx);
+       return ret;
+}
+
 /*
  * Copies the file resource specified by the lookup table entry @lte from the
  * input WIM to the output WIM that has its FILE * given by
 /*
  * Copies the file resource specified by the lookup table entry @lte from the
  * input WIM to the output WIM that has its FILE * given by