]> wimlib.net Git - wimlib/commitdiff
Various fixes
authorEric Biggers <ebiggers3@gmail.com>
Tue, 21 Aug 2012 01:20:29 +0000 (20:20 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 21 Aug 2012 01:20:29 +0000 (20:20 -0500)
programs/imagex.c
src/dentry.c
src/lookup_table.c
src/mount.c
src/symlink.c
tests/test-imagex

index ffd0d9451e0ebaf64493e3eb9ca98db54c9cb971..f83bbb0b1ded60aad5ba178557a264868df66b8f 100644 (file)
@@ -699,6 +699,7 @@ static int imagex_export(int argc, const char **argv)
                        imagex_error("Cannot specify a compression type that is "
                                     "not the same as that used in the "
                                     "destination WIM");
                        imagex_error("Cannot specify a compression type that is "
                                     "not the same as that used in the "
                                     "destination WIM");
+                       ret = -1;
                        goto done;
                }
                compression_type = wimlib_get_compression_type(dest_w);
                        goto done;
                }
                compression_type = wimlib_get_compression_type(dest_w);
index b62f53ae6d73e4dc46092e3170061e6a48ca390c..f5a3fe1476cabf07bae615680b07b2f22b001061 100644 (file)
@@ -419,6 +419,7 @@ struct file_attr_flag file_attr_flags[] = {
 int print_dentry(struct dentry *dentry, void *lookup_table)
 {
        const u8 *hash;
 int print_dentry(struct dentry *dentry, void *lookup_table)
 {
        const u8 *hash;
+       struct lookup_table_entry *lte;
 
        printf("[DENTRY]\n");
        printf("Length            = %"PRIu64"\n", dentry->length);
 
        printf("[DENTRY]\n");
        printf("Length            = %"PRIu64"\n", dentry->length);
@@ -446,12 +447,6 @@ int print_dentry(struct dentry *dentry, void *lookup_table)
        printf("Last Access Time  = %s", asctime(localtime(&access_time)));
        printf("Last Write Time   = %s", asctime(localtime(&mod_time)));
 
        printf("Last Access Time  = %s", asctime(localtime(&access_time)));
        printf("Last Write Time   = %s", asctime(localtime(&mod_time)));
 
-       hash = dentry_stream_hash(dentry, 0);
-       if (hash) {
-               printf("Hash              = 0x"); 
-               print_hash(hash);
-               putchar('\n');
-       }
        printf("Reparse Tag       = 0x%"PRIx32"\n", dentry->reparse_tag);
        printf("Hard Link Group   = 0x%"PRIx64"\n", dentry->hard_link);
        printf("Number of Alternate Data Streams = %hu\n", dentry->num_ads);
        printf("Reparse Tag       = 0x%"PRIx32"\n", dentry->reparse_tag);
        printf("Hard Link Group   = 0x%"PRIx64"\n", dentry->hard_link);
        printf("Number of Alternate Data Streams = %hu\n", dentry->num_ads);
@@ -466,7 +461,17 @@ int print_dentry(struct dentry *dentry, void *lookup_table)
        puts("\"");
        printf("Short Name Length = %hu\n", dentry->short_name_len);
        printf("Full Path (UTF-8) = \"%s\"\n", dentry->full_path_utf8);
        puts("\"");
        printf("Short Name Length = %hu\n", dentry->short_name_len);
        printf("Full Path (UTF-8) = \"%s\"\n", dentry->full_path_utf8);
-       print_lookup_table_entry(dentry_stream_lte(dentry, 0, lookup_table));
+       lte = dentry_stream_lte(dentry, 0, lookup_table);
+       if (lte) {
+               print_lookup_table_entry(lte);
+       } else {
+               hash = dentry_stream_hash(dentry, 0);
+               if (hash) {
+                       printf("Hash              = 0x"); 
+                       print_hash(hash);
+                       putchar('\n');
+               }
+       }
        for (u16 i = 0; i < dentry->num_ads; i++) {
                printf("[Alternate Stream Entry %u]\n", i);
                printf("Name = \"%s\"\n", dentry->ads_entries[i].stream_name_utf8);
        for (u16 i = 0; i < dentry->num_ads; i++) {
                printf("[Alternate Stream Entry %u]\n", i);
                printf("Name = \"%s\"\n", dentry->ads_entries[i].stream_name_utf8);
index a409947268068cb49a0d852e41b770ba4c922692..6515e9c35fbd53820bb258eea148fe338b323ba5 100644 (file)
@@ -288,7 +288,7 @@ void print_lookup_table_entry(struct lookup_table_entry *lte)
               lte->resource_entry.original_size);
        printf("Part Number       = %hu\n", lte->part_number);
        printf("Reference Count   = %u\n", lte->refcnt);
               lte->resource_entry.original_size);
        printf("Part Number       = %hu\n", lte->part_number);
        printf("Reference Count   = %u\n", lte->refcnt);
-       printf("Hash              = ");
+       printf("Hash              = 0x");
        print_hash(lte->hash);
        putchar('\n');
        printf("Flags             = ");
        print_hash(lte->hash);
        putchar('\n');
        printf("Flags             = ");
index de8fe001d8009a053668a537ef06362a22b74d28..19e8d5d700a573b39063a8f69b89ae44daecece2 100644 (file)
@@ -772,19 +772,22 @@ static void lte_list_change_lte_ptr(struct lookup_table_entry *lte,
 }
 
 
 }
 
 
-static int calculate_sha1sum_of_staging_file(struct lookup_table_entry *lte,
-                                            struct lookup_table *table)
+static int update_lte_of_staging_file(struct lookup_table_entry *lte,
+                                     struct lookup_table *table)
 {
        struct lookup_table_entry *duplicate_lte;
        int ret;
        u8 hash[SHA1_HASH_SIZE];
 {
        struct lookup_table_entry *duplicate_lte;
        int ret;
        u8 hash[SHA1_HASH_SIZE];
+       struct stat stbuf;
+
+       wimlib_assert(lte->staging_file_name);
 
        ret = sha1sum(lte->staging_file_name, hash);
        if (ret != 0)
                return ret;
 
 
        ret = sha1sum(lte->staging_file_name, hash);
        if (ret != 0)
                return ret;
 
+
        lookup_table_unlink(table, lte);
        lookup_table_unlink(table, lte);
-       copy_hash(lte->hash, hash);
 
        duplicate_lte = __lookup_resource(table, hash);
 
 
        duplicate_lte = __lookup_resource(table, hash);
 
@@ -793,11 +796,17 @@ static int calculate_sha1sum_of_staging_file(struct lookup_table_entry *lte,
 
                lte_list_change_lte_ptr(lte, duplicate_lte);
                duplicate_lte->refcnt += lte->refcnt;
 
                lte_list_change_lte_ptr(lte, duplicate_lte);
                duplicate_lte->refcnt += lte->refcnt;
-               list_splice(&duplicate_lte->lte_group_list,
-                           &lte->lte_group_list);
+               list_splice(&lte->lte_group_list,
+                           &duplicate_lte->lte_group_list);
 
                free_lookup_table_entry(lte);
        } else {
 
                free_lookup_table_entry(lte);
        } else {
+               if (stat(lte->staging_file_name, &stbuf) != 0) {
+                       ERROR_WITH_ERRNO("Failed to stat `%s'", lte->staging_file_name);
+                       return WIMLIB_ERR_STAT;
+               }
+               copy_hash(lte->hash, hash);
+               lte->resource_entry.original_size = stbuf.st_size;
                lookup_table_insert(table, lte);
        }
 
                lookup_table_insert(table, lte);
        }
 
@@ -822,7 +831,7 @@ static int rebuild_wim(WIMStruct *w, bool check_integrity)
         * lookup table entries. */
        DEBUG("Calculating SHA1 checksums for all new staging files.");
        list_for_each_entry_safe(lte, tmp, &staging_list, staging_list) {
         * lookup table entries. */
        DEBUG("Calculating SHA1 checksums for all new staging files.");
        list_for_each_entry_safe(lte, tmp, &staging_list, staging_list) {
-               ret = calculate_sha1sum_of_staging_file(lte, w->lookup_table);
+               ret = update_lte_of_staging_file(lte, w->lookup_table);
                if (ret != 0)
                        return ret;
        }
                if (ret != 0)
                        return ret;
        }
index dc5af4c6e4bf88fb8eaba1d6beb61920112557f7..d2a1f84fcc1d5af829fb3c5abf3a3e2c83e33897 100644 (file)
@@ -131,9 +131,9 @@ void *make_symlink_reparse_data_buf(const char *symlink_target, size_t *len_ret)
        /* XXX Fix absolute paths */
 
        u8 *p = buf;
        /* XXX Fix absolute paths */
 
        u8 *p = buf;
-       p = put_u16(p, 0); /* Substitute name offset */
+       p = put_u16(p, utf16_len); /* Substitute name offset */
        p = put_u16(p, utf16_len); /* Substitute name length */
        p = put_u16(p, utf16_len); /* Substitute name length */
-       p = put_u16(p, utf16_len); /* Print name offset */
+       p = put_u16(p, 0); /* Print name offset */
        p = put_u16(p, utf16_len); /* Print name length */
        p = put_u32(p, 1);
        p = put_bytes(p, utf16_len, name_utf16);
        p = put_u16(p, utf16_len); /* Print name length */
        p = put_u32(p, 1);
        p = put_bytes(p, utf16_len, name_utf16);
@@ -194,7 +194,7 @@ static int dentry_set_symlink_buf(struct dentry *dentry,
        wimlib_assert(dentry->num_ads == 0);
        wimlib_assert(dentry->ads_entries == NULL);
 
        wimlib_assert(dentry->num_ads == 0);
        wimlib_assert(dentry->ads_entries == NULL);
 
-       ads_entries[1].lte = lte;
+       ads_entries[0].lte = lte;
 
        /*dentry_free_ads_entries(dentry);*/
        dentry->num_ads = 2;
 
        /*dentry_free_ads_entries(dentry);*/
        dentry->num_ads = 2;
index 3f33a2fb84c9f7f7c3fe68689a1cc90220cd6cd4..9a7f4f0949b2a98735b7228a51191fe9b48934e9 100755 (executable)
@@ -11,23 +11,6 @@ imagex() {
        echo "imagex $@"
        ../imagex $@
 }
        echo "imagex $@"
        ../imagex $@
 }
-#diff() {
-       #echo "diff $@"
-       #/usr/bin/env diff $@
-#}
-
-#dd() {
-       #echo "dd $@"
-       #/usr/bin/env dd $@
-#}
-#stat() {
-       #echo "stat $@" 1>&2
-       #/usr/bin/env stat $@
-#}
-#cmp() {
-       #echo "cmp $@"
-       #/usr/bin/env cmp $@
-#}
 
 cleanup() {
        if [ -d tmp ] && mountpoint tmp > /dev/null; then
 
 cleanup() {
        if [ -d tmp ] && mountpoint tmp > /dev/null; then
@@ -565,27 +548,65 @@ rm -rf tmp
 
 # imagex export
 echo "Testing export of single image to new WIM"
 
 # imagex export
 echo "Testing export of single image to new WIM"
-imagex capture dir dir.wim
-imagex append dir2 dir.wim
-imagex export dir.wim dir new.wim
-test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 1;
+if ! imagex capture dir dir.wim; then
+       error "Failed to capture test WIM"
+fi
+if ! imagex append dir2 dir.wim; then
+       error "Failed to append image to test WIM"
+fi
+if ! imagex export dir.wim dir new.wim; then
+       error "Failed to export single image to new WIM"
+fi
+if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
+       error "Exporting single image to new WIM wasn't done correctly"
+fi
 echo "Testing export of single image to existing WIM"
 echo "Testing export of single image to existing WIM"
-imagex export dir.wim dir2 new.wim
-test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
+if ! imagex export dir.wim dir2 new.wim; then
+       error "Failed to export single image to existing WIM"
+fi
+if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
+       error "Exporting single image to existing WIM wasn't done correctly"
+fi
 echo "Testing export of single image to existing WIM using wrong compression type"
 echo "Testing export of single image to existing WIM using wrong compression type"
-! imagex export dir.wim dir2 new.wim newname --compress=maximum
+if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
+       error "Successfully exported image using wrong compression type"
+fi
 rm -f new.wim
 echo "Testing export of multiple images to new WIM"
 rm -f new.wim
 echo "Testing export of multiple images to new WIM"
-imagex export dir.wim all new.wim
-test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
-imagex capture dir2 new.wim newname
+if ! imagex export dir.wim all new.wim; then
+       error "Failed to export multiple images to new WIM"
+fi
+if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
+       error "Exporting multiple images to new WIM wasn't done correctly"
+fi
+if ! imagex capture dir2 new.wim newname; then
+       error "Failed to capture test WIM"
+fi
 echo "Testing export of multiple images to existing WIM"
 echo "Testing export of multiple images to existing WIM"
-imagex export dir.wim all new.wim
+if ! imagex export dir.wim all new.wim; then
+       error "Failed to export multiple images to existing WIM"
+fi
 echo "Testing export of multiple images to existing WIM with --boot"
 echo "Testing export of multiple images to existing WIM with --boot"
-imagex capture dir2 new.wim newname
-imagex info dir.wim --boot 1
-imagex export dir.wim all new.wim --boot
+if ! imagex capture dir2 new.wim newname; then
+       error "Failed to capture test WIM"
+fi
+if ! imagex info dir.wim --boot 1; then
+       error "Failed to set boot index on test WIM"
+fi
+if ! imagex export dir.wim all new.wim --boot; then
+       error "Failed to export multiple images to existing WIM with bootable image"
+fi
 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
-imagex capture dir2 new.wim newname
-imagex info dir.wim --boot 0
-! imagex export dir.wim all new.wim --boot
+if ! imagex capture dir2 new.wim newname; then
+       error "Failed to capture test WIM"
+fi
+if ! imagex info dir.wim --boot 0; then
+       error "Failed to clear boot index on test WIM"
+fi
+if imagex export dir.wim all new.wim --boot; then
+       error "Successfully exported multiple images with --boot but with no bootable images"
+fi
+
+echo "**********************************************************"
+echo "                     All tests passed                     "
+echo "**********************************************************"