Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Made it so adding symlinks works #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions extract-xiso.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@
#define S_ISDIR( x ) ( ( x ) & _S_IFDIR )
#define S_ISREG( x ) ( ( x ) & _S_IFREG )

#define realpath(x, y) _fullpath(y, x, 0)

#include "win32/getopt.c"
#if defined(_MSC_VER)
#include "win32/asprintf.c"
Expand Down Expand Up @@ -1722,24 +1724,30 @@ int write_tree( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep
context.progress = in_context->progress;
context.final_bytes = in_context->final_bytes;

if ( in_context->from == -1 ) {
if ( chdir( in_avl->filename ) == -1 ) chdir_err( in_avl->filename );
}

if ( ! err ) err = avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) write_file, &context, k_prefix, 0 );
if ( ! err ) err = avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) write_tree, &context, k_prefix, 0 );

if (!err && lseek(in_context->xiso, (xoff_t)in_avl->start_sector * XISO_SECTOR_SIZE, SEEK_SET) == -1) seek_err();
if (!err) err = avl_traverse_depth_first(in_avl->subdirectory, (traversal_callback)write_directory, (void*)in_context->xiso, k_prefix, 0);
if (!err && (pos = lseek(in_context->xiso, 0, SEEK_CUR)) == -1) seek_err();
if (!err && (pad = (int)((XISO_SECTOR_SIZE - (pos % XISO_SECTOR_SIZE)) % XISO_SECTOR_SIZE))) {
memset(sector, XISO_PAD_BYTE, pad);
if (write(in_context->xiso, sector, pad) != pad) write_err();
}

if ( ! err && in_context->from == -1 ) {
if ( chdir( ".." ) == -1 ) chdir_err( ".." );
}
char* rpwd = realpath( ".", NULL );
if ( ! rpwd ) {
read_err();
} else {
if ( in_context->from == -1 ) {
if ( chdir( in_avl->filename ) == -1 ) chdir_err( in_avl->filename );
}

if ( ! err ) err = avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) write_file, &context, k_prefix, 0 );
if ( ! err ) err = avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) write_tree, &context, k_prefix, 0 );

if (!err && lseek(in_context->xiso, (xoff_t)in_avl->start_sector * XISO_SECTOR_SIZE, SEEK_SET) == -1) seek_err();
if (!err) err = avl_traverse_depth_first(in_avl->subdirectory, (traversal_callback)write_directory, (void*)(uintptr_t)in_context->xiso, k_prefix, 0);
if (!err && (pos = lseek(in_context->xiso, 0, SEEK_CUR)) == -1) seek_err();
if (!err && (pad = (int)((XISO_SECTOR_SIZE - (pos % XISO_SECTOR_SIZE)) % XISO_SECTOR_SIZE))) {
memset(sector, XISO_PAD_BYTE, pad);
if (write(in_context->xiso, sector, pad) != pad) write_err();
}

if ( ! err && in_context->from == -1 ) {
if ( chdir( rpwd ) == -1 ) chdir_err( rpwd );
}
}
free(rpwd);

if ( context.path ) free( context.path );
} else {
Expand Down Expand Up @@ -1990,10 +1998,18 @@ int generate_avl_tree_local( dir_node_avl **out_root, int *io_n ) {
if ( S_ISDIR( sb.st_mode ) ) {
empty_dir = false;

if ( chdir( avl->filename ) == -1 ) chdir_err( avl->filename );
char* rpwd = realpath( ".", NULL );
if ( ! rpwd ) {
read_err();
} else {

if ( ! err ) err = generate_avl_tree_local( &avl->subdirectory, io_n );
if ( ! err && chdir( ".." ) == -1 ) chdir_err( ".." );
if ( ! err && chdir( avl->filename ) == -1 ) chdir_err( avl->filename );

if ( ! err ) err = generate_avl_tree_local( &avl->subdirectory, io_n );
if ( ! err && chdir( rpwd ) == -1 ) chdir_err( rpwd );

free( rpwd );
}
} else if ( S_ISREG( sb.st_mode ) ) {
empty_dir = false;
if ( sb.st_size > ULONG_MAX ) {
Expand Down