Skip to content

Commit

Permalink
Added debug/dry run mode
Browse files Browse the repository at this point in the history
This mode does not generate an appledouble file and instead prints out:
 - The input file (both local and absolute paths)
 - The output file
 - The copyfile flags that would have been used (printed in hexadecimal)
 - The the actual flags above that were valid (printed in hexadecimal)
  • Loading branch information
SiviourBla committed Aug 10, 2022
1 parent 6b73417 commit 801f451
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
26 changes: 21 additions & 5 deletions src/appledouble.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,26 @@ int MakeAppleDouble(ExecInfo *Info) {
}

//If copyfile outputs a value other than 0, it has failed
int ResultCode = copyfile(Info->Config.FPath, OutputPath, NULL, Info->Config.CFFlags);
if (ResultCode) {
fprintf(stderr, "Error: copyfile failed with error code %d!\nInput file: \"%s\"\nOutput file: \"%s\"\n", ResultCode, Info->Config.FPath, OutputPath);
fprintf(stderr, "Please refer to copyfile's error codes through 'man 3 copyfile' for more information\n");
if (!Info->Config.Opt_D) {
int ResultCode = copyfile(Info->Config.FPath, OutputPath, NULL, Info->Config.CFFlags);
if (ResultCode) {
fprintf(stderr, "Error: copyfile failed with error code %d!\nInput file: \"%s\"\nOutput file: \"%s\"\n", ResultCode, Info->Config.FPath, OutputPath);
fprintf(stderr, "Please refer to copyfile's error codes through 'man 3 copyfile' for more information\n");
}
return ResultCode;
//If debug mode is enabled, don't run copyfile and instead print debug info
} else {
copyfile_flags_t CopiedFlags = copyfile(Info->Config.FPath, OutputPath, NULL, Info->Config.CFFlags);
Info->Config.CFFlags -= COPYFILE_CHECK;
copyfile_flags_t FixedCopyFlags[] = {Info->Config.CFFlags, CopiedFlags};
printf("Debug/dry run mode active:\n"
" Input file (local path): \"%s\"\n"
" Input file: \"%s\"\n"
" Skipped output file: \"%s\"\n"
" Input flags: %xx\n"
" COPYFILE_CHECK flags: %xx"
"\n", OldFPath, Info->Config.FPath, OutputPath, FixedCopyFlags[0], FixedCopyFlags[1]);

return 0;
}
return ResultCode;
}
5 changes: 5 additions & 0 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ int ParseArgs(ExecInfo *Info, const int argc, const char *argv[]) {
case 'R':
Info->Config.Opt_R = 1;
break;
//Debug/dry run mode
case 'd':
Info->Config.CFFlags += COPYFILE_CHECK;
Info->Config.Opt_D = 1;
break;
//Copy POSIX and ACL information in addition to extended attributes
case 'a':
Info->Config.CFFlags += COPYFILE_SECURITY;
Expand Down
1 change: 1 addition & 0 deletions src/customDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct ExecConfig {
copyfile_flags_t CFFlags;
int Opt_R;
int Opt_rr;
int Opt_D;
char FPath[3334];
} ExecConfig;

Expand Down
3 changes: 2 additions & 1 deletion src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ void DisplayInfo(ExecInfo *Info, const int DisplayMode) {
" copyfile: man 3 copyfile\n"
"\n"
"Usage:\n"
" appledouble [-frRavhA] file\n"
" appledouble [-frRdavhA] file\n"
"\n"
"Options:\n"
" -f Overwrite any existing appledouble files\n"//COPYFILE_UNLINK + !COPYFILE_EXCL
" -r Follow symlinks\n"//!COPYFILE_NOFOLLOW
" -R Attempt to convert existing appledouble files\n"//!COPYFILE_NOFOLLOW
" -d Enables debug/dry run mode\n"//COPYFILE_CHECK
" -a Copy POSIX and ACL information in addition to extended attributes\n"//COPYFILE_SECURITY
" -v Display the version number\n"
" -h Display this help page\n"
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
int main(int argc, char *argv[]) {
ExecInfo Info = {
//Version Name
"1.1.1"
"1.2.0"
};
Info.Config.CFFlags = COPYFILE_XATTR | COPYFILE_PACK | COPYFILE_EXCL | COPYFILE_NOFOLLOW;
Info.Config.Opt_R = 0;
Expand Down

0 comments on commit 801f451

Please sign in to comment.