From 6518c2d246213357dde023a86d70195dd59f456b Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 17 May 2013 15:06:53 +0200 Subject: [PATCH] libite: Improve error handling for copyfile() and rsync() When using the simple rsync() or copyfile() functions of libite some error codes should not be interpreted as error. I.e., if a file or directory already exists when attempting to create it. Signed-off-by: Joachim Nilsson --- libite/copyfile.c | 1 + libite/rsync.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libite/copyfile.c b/libite/copyfile.c index d0867f8d..38fe6993 100644 --- a/libite/copyfile.c +++ b/libite/copyfile.c @@ -179,6 +179,7 @@ int copy_filep(FILE *src, FILE *dst) return errno; while (1) { + errno = 0; if (!fgets(buf, BUFSIZ, src)) { if (errno == EINTR) { clearerr(src); diff --git a/libite/rsync.c b/libite/rsync.c index 7a660e31..0f4082bc 100644 --- a/libite/rsync.c +++ b/libite/rsync.c @@ -62,7 +62,12 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file)) { errno = 0; copyfile(src, dst, 0); - if (errno) result++; + if (errno) { + if (errno == EEXIST) + errno = 0; + else + result++; + } } if (!fisdir(dst)) @@ -127,8 +132,12 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file)) static int makedir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode) { snprintf(buf, buf_len, "%s%s%s/", dir, fisslashdir(dir) ? "" : "/", name); - if (mkdir(buf, mode)) - return 1; + if (mkdir(buf, mode)) { + if (EEXIST != errno) + return 1; + + errno = 0; + } return 0; }