]> wimlib.net Git - wimlib/blobdiff - src/resource.c
write.c, lookup table.c: cleanup
[wimlib] / src / resource.c
index 5237b88a37fd646613770df5768e3f56625cd2ab..a7a831980b562e3915721ff62044d08e1da4ecb5 100644 (file)
@@ -576,7 +576,7 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte,
                        while (size) {
                                size_t bytes_to_read = min(WIM_CHUNK_SIZE, size);
                                size_t bytes_read = fread(buf, 1, bytes_to_read, wim_fp);
-                               
+
                                if (bytes_read != bytes_to_read)
                                        goto read_error;
                                ret = cb(buf, bytes_read, ctx_or_buf);
@@ -593,7 +593,11 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte,
        }
        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)
@@ -838,6 +842,29 @@ extract_wim_resource_to_fd(const struct wim_lookup_table_entry *lte,
        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;
+}
+
+/* Calculate the SHA1 message digest of a stream. */
+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