From: Eric Biggers Date: Tue, 21 Aug 2012 01:20:29 +0000 (-0500) Subject: Various fixes X-Git-Tag: v1.0.0~110 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=200bd141bea66770dd9845a95f2403d59956b931 Various fixes --- diff --git a/programs/imagex.c b/programs/imagex.c index ffd0d945..f83bbb0b 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -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"); + ret = -1; goto done; } compression_type = wimlib_get_compression_type(dest_w); diff --git a/src/dentry.c b/src/dentry.c index b62f53ae..f5a3fe14 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -419,6 +419,7 @@ struct file_attr_flag file_attr_flags[] = { 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); @@ -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))); - 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); @@ -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); - 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); diff --git a/src/lookup_table.c b/src/lookup_table.c index a4099472..6515e9c3 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -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); - printf("Hash = "); + printf("Hash = 0x"); print_hash(lte->hash); putchar('\n'); printf("Flags = "); diff --git a/src/mount.c b/src/mount.c index de8fe001..19e8d5d7 100644 --- a/src/mount.c +++ b/src/mount.c @@ -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 stat stbuf; + + wimlib_assert(lte->staging_file_name); ret = sha1sum(lte->staging_file_name, hash); if (ret != 0) return ret; + lookup_table_unlink(table, lte); - copy_hash(lte->hash, 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; - list_splice(&duplicate_lte->lte_group_list, - <e->lte_group_list); + list_splice(<e->lte_group_list, + &duplicate_lte->lte_group_list); 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); } @@ -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) { - 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; } diff --git a/src/symlink.c b/src/symlink.c index dc5af4c6..d2a1f84f 100644 --- a/src/symlink.c +++ b/src/symlink.c @@ -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; - 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); /* 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); @@ -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); - ads_entries[1].lte = lte; + ads_entries[0].lte = lte; /*dentry_free_ads_entries(dentry);*/ dentry->num_ads = 2; diff --git a/tests/test-imagex b/tests/test-imagex index 3f33a2fb..9a7f4f09 100755 --- a/tests/test-imagex +++ b/tests/test-imagex @@ -11,23 +11,6 @@ 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 @@ -565,27 +548,65 @@ rm -rf tmp # 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" -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" -! 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" -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" -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" -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)" -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 "**********************************************************"