diff --git a/src/appledouble.c b/src/appledouble.c index a704c31..9bbd937 100644 --- a/src/appledouble.c +++ b/src/appledouble.c @@ -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; } \ No newline at end of file diff --git a/src/args.c b/src/args.c index 7c975f8..f385f2b 100644 --- a/src/args.c +++ b/src/args.c @@ -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; diff --git a/src/customDefs.h b/src/customDefs.h index 49134e0..1e4f65c 100644 --- a/src/customDefs.h +++ b/src/customDefs.h @@ -15,6 +15,7 @@ typedef struct ExecConfig { copyfile_flags_t CFFlags; int Opt_R; int Opt_rr; + int Opt_D; char FPath[3334]; } ExecConfig; diff --git a/src/info.c b/src/info.c index 612d222..c05d5a4 100644 --- a/src/info.c +++ b/src/info.c @@ -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" diff --git a/src/main.c b/src/main.c index c80603e..9da2518 100644 --- a/src/main.c +++ b/src/main.c @@ -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;