Added --noremove option

This commit is contained in:
L. Bradley LaBoon 2017-05-10 20:31:40 -04:00
parent 0ca6ba656d
commit 2cb8f3cc7f

View File

@ -39,8 +39,9 @@ void printHelp()
printf("Turn destdir into a clone of srcdir.\n\n"); printf("Turn destdir into a clone of srcdir.\n\n");
printf("Options:\n"); printf("Options:\n");
printf(" --test\tRun in test mode.\n"); printf(" --test\t\tRun in test mode\n");
printf(" --help\tPrint this help and quit.\n\n"); printf(" --noremove\tDon't remove any files in destdir\n");
printf(" --help\t\tPrint this help and quit\n\n");
printf("Report bugs to L. Bradley LaBoon <me@bradleylaboon.com>\n"); printf("Report bugs to L. Bradley LaBoon <me@bradleylaboon.com>\n");
printf("backly home page: <http://git.bradleylaboon.com/backly.git>\n"); printf("backly home page: <http://git.bradleylaboon.com/backly.git>\n");
@ -303,7 +304,7 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int srcArg = 0, destArg = 0; int srcArg = 0, destArg = 0;
int testMode = 0; int testMode = 0, remove = 1;
// Parse arguments // Parse arguments
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
@ -313,6 +314,8 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "--test") == 0) { } else if (strcmp(argv[i], "--test") == 0) {
testMode = 1; testMode = 1;
printf("***Operating in test mode.***\n"); printf("***Operating in test mode.***\n");
} else if (strcmp(argv[i], "--noremove") == 0) {
remove = 0;
} else if (srcArg == 0) { } else if (srcArg == 0) {
srcArg = i; srcArg = i;
} else { } else {
@ -362,6 +365,7 @@ int main(int argc, char **argv)
closedir(dir); closedir(dir);
// Remove files from the destination that don't exist in the source // Remove files from the destination that don't exist in the source
if (remove)
removeMissing(srcDir, strlen(srcDir), destDir, strlen(destDir), testMode); removeMissing(srcDir, strlen(srcDir), destDir, strlen(destDir), testMode);
// Copy new files and overwrite existing files if different // Copy new files and overwrite existing files if different