redmine

Bugfix try

Fixing the bug with clsync exit due to rsync's
exit on 11 exitcode. Rsync was exiting due to
deletion of "exclude list file" between
"include list" files commits to rsync processes
... ... @@ -56,4 +56,59 @@ char *fd2fpath_malloc(int fd) {
return fpath;
}
/**
* @brief Copies file
*
* @param[in] path_from Source file path
* @param[in] path_to Destination file path
*
* @retval zero Successfully copied
* @retval non-zero Got error, while copying
*
*/
int fileutils_copy(char *path_from, char *path_to) {
char buf[BUFSIZ];
FILE *from, *to;
from = fopen(path_from, "r");
if(from == NULL) {
printf_e("Error: fileutils_copy(\"%s\", \"%s\"): Cannot open file \"%s\" for reading: %s (errno: %i)\n",
path_from, path_to, path_from, strerror(errno), errno);
return errno;
}
to = fopen(path_to, "w");
if(to == NULL) {
printf_e("Error: fileutils_copy(\"%s\", \"%s\"): Cannot open file \"%s\" for writing: %s (errno: %i)\n",
path_from, path_to, path_to, strerror(errno), errno);
return errno;
}
while(!feof(from)) {
int err;
size_t r, w;
r = fread(buf, 1, BUFSIZ, from);
if((err=ferror(from))) {
printf_e("Error: fileutils_copy(\"%s\", \"%s\"): Cannot read from file \"%s\": %s (errno: %i)\n",
path_from, path_to, path_from, strerror(errno), errno);
return errno; // CHECK: Is the "errno" should be used in fread() case?
}
w = fwrite(buf, 1, r, to);
if((err=ferror(to))) {
printf_e("Error: fileutils_copy(\"%s\", \"%s\"): Cannot write to file \"%s\": %s (errno: %i)\n",
path_from, path_to, path_to, strerror(errno), errno);
return errno; // CHECK: is the "errno" should be used in fwrite() case?
}
if(r != w) {
printf_e("Error: fileutils_copy(\"%s\", \"%s\"): Got error while writing to file \"%s\" (%u != %u): %s (errno: %i)\n",
path_from, path_to, path_to, r, w, strerror(errno), errno);
return errno; // CHECK: is the "errno" should be used in case "r != w"?
}
}
return 0;
}
... ...
... ... @@ -19,3 +19,5 @@
extern char *fd2fpath_malloc(int fd);
extern int fileutils_copy(char *path_from, char *path_to);
... ...
... ... @@ -1019,12 +1019,31 @@ gboolean sync_idle_dosync_collectedevents_listpush(gpointer fpath_gp, gpointer e
}
// RSYNC case
if(*linescount_p >= options_p->rsyncinclimit) {
if(options_p->rsyncinclimit && (*linescount_p >= options_p->rsyncinclimit)) {
int ret;
// TODO: optimize this out {
char newexc_path[PATH_MAX+1];
if((ret=sync_idle_dosync_collectedevents_uniqfname(options_p, newexc_path, "exclist"))) {
printf_e("Error: sync_idle_dosync_collectedevents_listcreate: Cannot get unique file name.\n");
exit(ret);
}
if((ret=fileutils_copy(dosync_arg_p->excf_path, newexc_path))) {
printf_e("Error: sync_idle_dosync_collectedevents_listcreate: Cannot copy file \"%s\" to \"%s\".\n", dosync_arg_p->excf_path, newexc_path);
exit(ret);
}
// }
// That's required to copy excludes' list file for every rsync execution.
// The problem appears do to unlink()-ing the excludes' list file on callback function
// "sync_idle_dosync_collectedevents_cleanup()" of every execution.
if((ret=sync_idle_dosync_collectedevents_commitpart(dosync_arg_p))) {
printf_e("Error: sync_idle_dosync_collectedevents_listpush(): Cannot commit list-file \"%s\": %s (errno: %i)\n", dosync_arg_p->outf_path, strerror(ret), ret);
exit(ret); // TODO: replace with kill(0, ...);
}
strcpy(dosync_arg_p->excf_path, newexc_path); // TODO: optimize this out
if((ret=sync_idle_dosync_collectedevents_listcreate(dosync_arg_p, "list"))) {
printf_e("Error: sync_idle_dosync_collectedevents_listpush(): Cannot create new list-file: %s (errno: %i)\n", strerror(ret), ret);
exit(ret); // TODO: replace with kill(0, ...);
... ...