Skip to content

Commit

Permalink
Merge pull request #15 from mariux64/cmirror-next
Browse files Browse the repository at this point in the history
cmirror next
  • Loading branch information
donald authored Aug 23, 2022
2 parents 1c765e9 + 85fdb78 commit 14bd1ac
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions cmirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static const char *log_prefix;
static int noisy_abort;

static void warn(const char *restrict fmt, ...) {
static G_GNUC_PRINTF(1, 2) void warn(const char *restrict fmt, ...) {
if (log_prefix)
fprintf(stderr, "%s: ", log_prefix);
va_list ap;
Expand All @@ -45,7 +45,7 @@ static void warn(const char *restrict fmt, ...) {
va_end(ap);
}

static G_NORETURN void die(const char *restrict fmt, ...) {
static G_NORETURN G_GNUC_PRINTF(1, 2) void die(const char *restrict fmt, ...) {
if (fmt) {
if (log_prefix)
fprintf(stderr, "%s: ", log_prefix);
Expand Down Expand Up @@ -181,7 +181,7 @@ static struct FileInfo *fileinfo_lstat(char *path) {
fi->target = g_malloc(sb.st_size + 1);
int res = readlink(path, fi->target, sb.st_size+1);
if (res == -1)
die("readlink %s: %M\n", path);
die("readlink %s: %m\n", path);
if (res > sb.st_size)
die("readlink %s: target string to long\n", path);
fi->target[res] = '\0';
Expand Down Expand Up @@ -302,7 +302,7 @@ static char data_buffer[10240+2];

static void fileop_mknod(char *path, char type, dev_t rdev) {
if (fileop_debug)
warn("fileop: mknod %s %c %d\n", path, type, rdev);
warn("fileop: mknod %s %c %lu\n", path, type, rdev);
if (fileop_noop)
return;
mode_t mode;
Expand Down Expand Up @@ -410,7 +410,7 @@ static void fileop_lchown(uid_t uid, gid_t gid, char *path) {

static void fileop_lmtime(time_t mtime, char *path) {
if (fileop_debug)
warn("fileop: lmtime %d %s\n", mtime, path);
warn("fileop: lmtime %ld %s\n", mtime, path);
if (fileop_noop)
return;
struct timespec timespec[2] = { { 0, UTIME_OMIT } , { mtime, 0 } };
Expand Down Expand Up @@ -501,7 +501,7 @@ static void add_clean_dir(char *dir) {
GError *error;
GDir *d = g_dir_open(dir, 0, &error);
if (!d)
die("%s %s\n", error->message);
die("%s: %s\n", dir, error->message);
const char *entry;
while ( (entry = g_dir_read_name(d)) ) {
char *path = g_strdup_printf("%s/%s", dir, entry);
Expand All @@ -515,7 +515,7 @@ static void add_clean_dir(char *dir) {
}

static void out_of_the_way(FileInfo *fi) {
if (fi->type == 'D') {
if (fi->type == 'D' && !fileop_noop) {
char *deleteme = g_strdup_printf("%s.deleteme", fi->name);
fileop_mv(fi->name, deleteme);
CLEAN_DIRS = g_slist_prepend(CLEAN_DIRS, deleteme);
Expand Down Expand Up @@ -544,10 +544,10 @@ static ssize_t receive_record(FILE *in, char *buffer, size_t buflen) {
return 0;
unsigned int len = ntohs(*(uint16_t *)b);
if (len > buflen)
die("data overrun %d > %d\n", len, buflen);
die("data overrun %u > %lu\n", len, buflen);
size_t l2 = fread(buffer, 1, len, in);
if (l2 != len)
die("data underrun %d != %d\n", l1, l2);
die("data underrun %lu != %lu\n", l1, l2);
return len;
}

Expand All @@ -565,7 +565,7 @@ static void receive_file(FILE *in, char *filename, off_t expected_size, mode_t p
if(l2 == -1)
die("%s: %m\n", filename);
if (l2 != l1)
die("%s: short write\n");
die("%s: short write\n", filename);
expected_size -= l2;
}
fdatasync(fd);
Expand Down Expand Up @@ -913,16 +913,19 @@ static void slave(char *slave_path) {
fileop_rm(path);
}
}
GSList *d = CLEAN_DIRS;
while (d) {
if (!quiet)
warn("rm -r %s\n", d->data);
d = d->next;
}
}
if (reduce)
return;

GSList *d = CLEAN_DIRS;
while (d) {
char *path = (char *)d->data;
if (!quiet)
warn("rm -r %s\n", path);
fileop_rmdir_recurse(path);
d = d->next;
}

DIR_MTIME_QUEUE = g_list_reverse(DIR_MTIME_QUEUE);
for (GList *e = DIR_MTIME_QUEUE ; e != NULL ; e = e->next ) {
DirMtime *mt = e->data;
Expand All @@ -937,7 +940,7 @@ static void slave(char *slave_path) {
if (statbuf.st_mtime == mt->mtime)
continue;
if (!quiet)
warn("fix directory mtime of %s -> %d\n", mt->path, mt->mtime);
warn("fix directory mtime of %s -> %ld\n", mt->path, mt->mtime);
if (!fileop_noop) {
struct timespec timespec[2] = { { 0, UTIME_OMIT } , { mt->mtime, 0 } };
if (utimensat(AT_FDCWD, mt->path, timespec, AT_SYMLINK_NOFOLLOW) == -1)
Expand Down Expand Up @@ -1257,7 +1260,7 @@ static void master(char *master_path, char *target) {
unsetenv("SSH_ORIGINAL_COMMAND");

execvp(args->pdata[0], (char **)args->pdata);
die("exec %s: %m\n", args->pdata[0]);
die("exec %s: %m\n", (char *)args->pdata[0]);
}
else if (pid == -1)
die("fork: %m");
Expand Down

0 comments on commit 14bd1ac

Please sign in to comment.