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);
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("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);
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);
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 = ");
}
-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);
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);
}
* 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;
}
/* 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);
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;
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
# 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 "**********************************************************"