]> mj.ucw.cz Git - libucw.git/commitdiff
Added sync_dir().
authorMartin Mares <mj@ucw.cz>
Sun, 15 Aug 2004 12:09:57 +0000 (12:09 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 15 Aug 2004 12:09:57 +0000 (12:09 +0000)
lib/Makefile
lib/lib.h
lib/sync.c [new file with mode: 0644]

index f3e0529c2704c142ed7812b7158aa72e8fa6565e..df0d046aeb610e85c99b99e274d9db887ba3716b 100644 (file)
@@ -22,7 +22,8 @@ LIBSH_MODS= \
        mainloop exitstatus runcmd sighandler \
        lizard lizard-safe adler32 \
        md5 md5hex \
-       base64 base224
+       base64 base224 \
+       sync
 
 ifdef CONFIG_OWN_REGEX
 include lib/regex/Makefile
index c58d83da573283fa5385a6a4dab61123bc789be9..2a106e7ff50d234d65ea46c7b76114d53c64f9cc 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -207,6 +207,10 @@ void echo_command_v(byte *buf, int size, byte *cmd, va_list args);
 int careful_read(int fd, void *buf, int len);
 int careful_write(int fd, void *buf, int len);
 
+/* sync.c */
+
+void sync_dir(byte *name);
+
 /* sighandler.c */
 
 typedef int (*sh_sighandler_t)(int);
diff --git a/lib/sync.c b/lib/sync.c
new file mode 100644 (file)
index 0000000..76bd590
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *     Sherlock Library -- Syncing Directories
+ *
+ *     (c) 2004 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+void
+sync_dir(byte *name)
+{
+  int fd = open(name, O_RDONLY | O_DIRECTORY);
+  if (fd < 0)
+    goto err;
+  int err = fsync(fd);
+  close(fd);
+  if (err >= 0)
+    return;
+ err:
+  log(L_ERROR, "Unable to sync directory %s: %m", name);
+}