6 Commits
v1.1 ... v1.30

2 changed files with 51 additions and 43 deletions

View File

@ -3,14 +3,14 @@ DESTDIR ?=
PREFIX ?= /usr/local PREFIX ?= /usr/local
# Build flags # Build flags
FLAGS = -std=gnu99 OPTS = -std=gnu99
# Build rules # Build rules
all: backly all: backly
.PHONY: all install clean .PHONY: all install clean
backly: backly.c Makefile backly: backly.c Makefile
gcc $(FLAGS) -o backly backly.c gcc $(OPTS) $(CFLAGS) -o backly backly.c
install: backly install: backly
install -Dm 0755 backly $(DESTDIR)/$(PREFIX)/bin/backly install -Dm 0755 backly $(DESTDIR)/$(PREFIX)/bin/backly

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");
@ -259,7 +260,7 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
// Only copy file if it doesn't exist or has changed // Only copy file if it doesn't exist or has changed
if (needToCopy == 1) { if (needToCopy == 1) {
printf("+ %s 100.00%", itemSrc + srcPrefix); printf("+ %s ", itemSrc + srcPrefix);
fflush(stdout); fflush(stdout);
if (testMode == 0) { if (testMode == 0) {
int pid = fork(); int pid = fork();
@ -267,11 +268,11 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
fprintf(stderr, "Could not fork: %s\n", strerror(errno)); fprintf(stderr, "Could not fork: %s\n", strerror(errno));
continue; continue;
} else if (pid == 0) { } else if (pid == 0) {
execlp("cp", "cp", "-f --preserve=timestamps", itemSrc, itemDest, (char *) NULL); execlp("cp", "cp", "-f", "-P", "--preserve=timestamps,links", itemSrc, itemDest, (char *) NULL);
} else { } else {
struct stat srcStat, destStat; struct stat srcStat, destStat;
double pDone = 0; double pDone = 0;
int numPrinted = 7; int numPrinted = 0;
if (stat(itemSrc, &srcStat) != -1) { if (stat(itemSrc, &srcStat) != -1) {
while (waitpid(pid, NULL, WNOHANG) == 0) { while (waitpid(pid, NULL, WNOHANG) == 0) {
if (stat(itemDest, &destStat) == -1) if (stat(itemDest, &destStat) == -1)
@ -285,6 +286,10 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
fflush(stdout); fflush(stdout);
} }
} }
for (int i = 0; i < numPrinted; i++)
printf("\b \b");
printf("100.00%%");
fflush(stdout);
} }
} }
printf("\n"); printf("\n");
@ -299,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++) {
@ -309,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 {
@ -358,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