Message ID | 20160907061103.11873-1-zajec5@gmail.com |
---|---|
State | Changes Requested |
Headers | show |
Hi, On 07/09/2016 08:11:03 CEST, Rafał Miłecki wrote: > + dir_fd = open(dirname(path), O_RDONLY); > + if (dir_fd) { This should be dir_fd != -1, as -1 is returned when an error occurs in open(). > + fsync(dir_fd); > + close(dir_fd); > + } Cheers, Vittorio
diff --git a/file.c b/file.c index 7e1e4e6..86d9032 100644 --- a/file.c +++ b/file.c @@ -23,6 +23,7 @@ #include <stdbool.h> #include <unistd.h> #include <fcntl.h> +#include <libgen.h> #include <stdio.h> #include <ctype.h> #include <glob.h> @@ -801,11 +802,20 @@ done: free(path); uci_close_stream(f1); if (do_rename) { + int dir_fd; + path = realpath(p->path, NULL); if (!path || rename(filename, path)) { unlink(filename); UCI_THROW(ctx, UCI_ERR_IO); } + + dir_fd = open(dirname(path), O_RDONLY); + if (dir_fd) { + fsync(dir_fd); + close(dir_fd); + } + free(path); } free(filename);