Skip to content

Commit 7f13908

Browse files
committed
Don't fail on empty directories
Properly write empty directories
1 parent 0a25b32 commit 7f13908

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

extract-xiso.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,16 @@ int traverse_xiso( int in_xiso, dir_node *in_dir_node, xoff_t in_dir_start, char
12051205

12061206
if ( ! err ) {
12071207
if ( tmp == XISO_PAD_SHORT ) {
1208+
if ( l_offset == 0 ) { // Directory is empty
1209+
if (in_mode == k_generate_avl) {
1210+
avl_insert(in_root, EMPTY_SUBDIRECTORY);
1211+
}
1212+
goto end_traverse;
1213+
}
1214+
12081215
l_offset = l_offset * XISO_DWORD_SIZE + ( XISO_SECTOR_SIZE - ( l_offset * XISO_DWORD_SIZE ) % XISO_SECTOR_SIZE );
12091216
err = lseek( in_xiso, in_dir_start + (xoff_t) l_offset, SEEK_SET ) == -1 ? 1 : 0;
1210-
1217+
12111218
if ( ! err ) goto read_entry; // me and my silly comments
12121219
} else {
12131220
l_offset = tmp;
@@ -1254,7 +1261,7 @@ int traverse_xiso( int in_xiso, dir_node *in_dir_node, xoff_t in_dir_start, char
12541261

12551262
avl->file_size = dir->file_size;
12561263
avl->old_start_sector = dir->start_sector;
1257-
1264+
12581265
if ( avl_insert( in_root, avl ) == k_avl_error ) misc_err( "this iso appears to be corrupt\n", 0, 0, 0 );
12591266
}
12601267
}
@@ -1299,7 +1306,10 @@ int traverse_xiso( int in_xiso, dir_node *in_dir_node, xoff_t in_dir_start, char
12991306
if ( ( err = mkdir( dir->filename, 0755 ) ) ) mkdir_err( dir->filename );
13001307
if ( ! err && dir->start_sector && ( err = chdir( dir->filename ) ) ) chdir_err( dir->filename );
13011308
}
1302-
if ( ! err && in_mode != k_list && in_mode != k_generate_avl ) exiso_log( "creating %s (0 bytes) [OK]\n", path );
1309+
if( ! err && in_mode != k_generate_avl ) {
1310+
exiso_log("%s%s%s%s (0 bytes)", in_mode == k_extract ? "creating " : "", in_path, dir->filename, PATH_CHAR_STR); flush();
1311+
exiso_log("\n");
1312+
}
13031313
}
13041314
}
13051315

@@ -1352,6 +1362,8 @@ int traverse_xiso( int in_xiso, dir_node *in_dir_node, xoff_t in_dir_start, char
13521362
}
13531363
}
13541364

1365+
end_traverse:
1366+
13551367
if ( dir->filename ) free( dir->filename );
13561368

13571369
if ( ( dir = dir->parent ) ) goto left_processed;
@@ -1725,6 +1737,10 @@ int write_tree( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep
17251737
}
17261738

17271739
if ( context.path ) free( context.path );
1740+
} else {
1741+
memset(sector, XISO_PAD_BYTE, XISO_SECTOR_SIZE);
1742+
if ((pos = lseek(in_context->xiso, in_avl->start_sector * XISO_SECTOR_SIZE, SEEK_SET)) == -1) seek_err();
1743+
if (!err && write(in_context->xiso, sector, XISO_SECTOR_SIZE) != XISO_SECTOR_SIZE) write_err();
17281744
}
17291745
}
17301746
}
@@ -1841,7 +1857,11 @@ int calculate_directory_offsets( dir_node_avl *in_avl, unsigned long *io_current
18411857
wdsafp_context context;
18421858

18431859
if ( in_avl->subdirectory ) {
1844-
if ( in_avl->subdirectory == EMPTY_SUBDIRECTORY ) in_avl->start_sector = 0;
1860+
if (in_avl->subdirectory == EMPTY_SUBDIRECTORY) {
1861+
in_avl->start_sector = *io_current_sector;
1862+
in_avl->file_size = XISO_SECTOR_SIZE;
1863+
*io_current_sector += 1;
1864+
}
18451865
else {
18461866
context.current_sector = io_current_sector;
18471867
context.dir_start = (xoff_t) ( in_avl->start_sector = *io_current_sector ) * XISO_SECTOR_SIZE;
@@ -1873,6 +1893,8 @@ int calculate_total_files_and_bytes( dir_node_avl *in_avl, void *in_context, int
18731893
if ( in_avl->subdirectory ) {
18741894
if ( in_avl->subdirectory != EMPTY_SUBDIRECTORY ) {
18751895
avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) calculate_total_files_and_bytes, nil, k_prefix, 0 );
1896+
} else {
1897+
s_total_bytes += XISO_SECTOR_SIZE;
18761898
}
18771899
} else {
18781900
++s_total_files;

0 commit comments

Comments
 (0)