Skip to content

Commit 2e8ce27

Browse files
committed
unadf: fix extracting tree for read-only directories, #91
Recent versions of unadf (after 0.7.12) sets permissions on extracted files and directories. In case of directories, setting the permissions made impossible to extract contents of read-only directories (at least using default call, extracting complete directory tree). Setting initially permissions allowing to write into directories and then, after extracting the contents, updating them as set in ADF fixes the issue.
1 parent b2c9c17 commit 2e8ce27

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ include ( CheckFunctionExists )
119119
include ( CheckSymbolExists )
120120

121121

122+
# Check filesystem functions
123+
124+
check_symbol_exists ( chmod "sys/stat.h" HAVE_CHMOD )
125+
if ( ${HAVE_CHMOD} )
126+
add_compile_definitions ( HAVE_CHMOD=1 )
127+
endif()
128+
129+
122130
# Check backtrace
123131

124132
check_function_exists ( backtrace HAVE_BACKTRACE )

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ AC_TYPE_UINT32_T
129129
AC_TYPE_UINT8_T
130130

131131
# Check functions
132+
AC_CHECK_FUNCS(chmod, AC_DEFINE([HAVE_CHMOD], [1]))
132133
AC_CHECK_FUNCS(strnlen, AC_DEFINE([HAVE_STRNLEN], [1]))
133134
AC_CHECK_FUNCS(strndup, AC_DEFINE([HAVE_STRNDUP], [1]))
134135
AC_CHECK_FUNCS(mempcpy, AC_DEFINE([HAVE_MEMPCPY], [1]))

examples/unadf.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void set_file_date(char *out, struct AdfEntry *e);
9292
void mkdir_if_needed(char *path, mode_t perms);
9393
mode_t permissions(struct AdfEntry *e);
9494
void fix_win32_filename(char *name);
95+
void set_permissions(const char * const path, const mode_t perms);
9596
void print_error(const char *s);
9697

9798
int main(int argc, char *argv[]) {
@@ -390,7 +391,8 @@ void extract_tree(struct AdfVolume *vol, struct AdfList *node, char *path)
390391
if (e->type == ADF_ST_DIR) {
391392
if (!pipe_mode) {
392393
printf("x - %s/\n", out);
393-
mkdir_if_needed(out, permissions(e));
394+
mkdir_if_needed(out, 0777 ); // temp. permissionss
395+
// ("w" is needed for extraction)
394396
}
395397
}
396398
else if (e->type == ADF_ST_FILE) {
@@ -414,6 +416,7 @@ void extract_tree(struct AdfVolume *vol, struct AdfList *node, char *path)
414416
// set timestamp
415417
if (!pipe_mode) {
416418
set_file_date(out, e);
419+
set_permissions( out, permissions(e) ); // real permissions
417420
}
418421

419422
free(out);
@@ -813,6 +816,26 @@ FILETIME getFileTime( time_t time )
813816
#endif
814817

815818

819+
#ifdef HAVE_CHMOD
820+
#include <sys/stat.h>
821+
822+
void set_permissions( const char * const path,
823+
const mode_t perms )
824+
{
825+
if ( chmod( path, perms ) != 0 )
826+
perror( path );
827+
// fprintf (stderr, "%s: real\n", __func__ );
828+
}
829+
#else
830+
void set_permissions( const char * const path,
831+
const mode_t perms )
832+
{
833+
(void) path, (void) perms;
834+
// fprintf (stderr, "%s: fake\n", __func__ );
835+
}
836+
#endif
837+
838+
816839
#ifdef DEBUG_UNADF
817840
void adfPrintBacktrace(void);
818841
#endif

0 commit comments

Comments
 (0)