[vhffs-dev] [1531] added mtime support to vhffsfssync |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1531
Author: gradator
Date: 2010-01-09 20:38:37 +0100 (Sat, 09 Jan 2010)
Log Message:
-----------
added mtime support to vhffsfssync
Modified Paths:
--------------
trunk/vhffs-fssync/vhffsfssync_master.c
trunk/vhffs-fssync/vhffsfssync_slave.c
Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c 2010-01-09 17:53:43 UTC (rev 1530)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2010-01-09 19:38:37 UTC (rev 1531)
@@ -434,6 +434,9 @@
void vhffsfssync_net_destroy_file(vhffsfssync_conn *conn, vhffsfssync_net_message_file *filemsg) {
+ struct stat st;
+ st.st_mtime=0;
+
conn->messages = g_list_remove(conn->messages, (vhffsfssync_net_message*)filemsg);
conn->messages_num--;
@@ -447,7 +450,12 @@
}
}
- vhffsfssync_net_send_event(conn, g_strdup_printf("close%c%s%c", '\0', filemsg->file->file_pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ // get mtime
+ if( fstat(fileno(filemsg->file->file_stream), &st) < 0 ) {
+ fprintf(stderr, "fstat() failed on %s: %s\n", filemsg->file->file_pathname, strerror(errno));
+ }
+
+ vhffsfssync_net_send_event(conn, g_strdup_printf("close%c%s%c%ld%c", '\0', filemsg->file->file_pathname, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_net_file_close(conn, filemsg->file);
free(filemsg);
}
@@ -811,14 +819,14 @@
vhffsfssync_net_send_file(conn, pathname);
}
else if( S_ISDIR(st.st_mode) ) {
- vhffsfssync_net_send_event(conn, g_strdup_printf("mkdir%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("mkdir%c%s%c%ld%c", '\0', pathname, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
else if( S_ISLNK(st.st_mode) ) {
char *linkto;
linkto = malloc(st.st_size +1);
if( readlink(pathname, linkto, st.st_size) >= 0 ) {
linkto[st.st_size] = '\0';
- vhffsfssync_net_send_event(conn, g_strdup_printf("symlink%c%s%c%s%c", '\0', pathname, '\0', linkto, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("symlink%c%s%c%s%c%ld%c", '\0', pathname, '\0', linkto, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
free(linkto);
}
@@ -999,9 +1007,13 @@
d = opendir(pathname);
if(d) {
struct dirent *dir;
+ struct stat std;
GString *msg = g_string_sized_new(1024);
- g_string_append_printf(msg, "ls%c%s%c", '\0', pathname, '\0');
+ std.st_mtime = 0;
+ lstat(pathname, &std);
+ g_string_append_printf(msg, "ls%c%s%c%ld%c", '\0', pathname, '\0', std.st_mtime, '\0');
+
while( (dir = readdir(d)) ) {
if( strcmp(dir->d_name, ".") && strcmp(dir->d_name, "..") ) {
char *path = g_strdup_printf("%s/%s", pathname, dir->d_name);
@@ -1305,7 +1317,7 @@
printf("==> MKDIR %s\n", pathname);
#endif
vhffsfssync_add_watch(inotifyfd, pathname, VHFFSFSSYNC_WATCH_MASK);
- vhffsfssync_net_broadcast_event( g_strdup_printf("mkdir%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_event( g_strdup_printf("mkdir%c%s%c%ld%c", '\0', pathname, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
/* there is a short delay between the mkdir() and the add_watch(),
we need to send events about the data which have already been written */
vhffsfssync_fake_events_recursively( inotifyfd, pathname );
@@ -1321,7 +1333,7 @@
#if DEBUG_INOTIFY
printf("==> SYMLINK %s -> %s\n", pathname, linkto);
#endif
- vhffsfssync_net_broadcast_event( g_strdup_printf("symlink%c%s%c%s%c", '\0', pathname, '\0', linkto, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+ vhffsfssync_net_broadcast_event( g_strdup_printf("symlink%c%s%c%s%c%ld%c", '\0', pathname, '\0', linkto, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
free(linkto);
if(ret < 0) {
Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c 2010-01-09 17:53:43 UTC (rev 1530)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c 2010-01-09 19:38:37 UTC (rev 1531)
@@ -46,6 +46,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <getopt.h>
+#include <utime.h>
/* -- network stuff -- */
@@ -88,7 +89,7 @@
// events protos
int vhffsfssync_remove(char *pathname);
-int vhffsfssync_mkdir(char *pathname, mode_t mode);
+int vhffsfssync_mkdir(char *pathname, mode_t mode, int long long mtime);
int vhffsfssync_checkfile(vhffsfssync_conn *conn, char *path, char *type, int long long size, int long long mtime);
int vhffsfssync_event(vhffsfssync_conn *conn, char *event);
int vhffsfssync_parse(vhffsfssync_conn *conn);
@@ -259,9 +260,10 @@
// the content of pathname is modified
-int vhffsfssync_mkdir(char *pathname, mode_t mode) {
+int vhffsfssync_mkdir(char *pathname, mode_t mode, int long long mtime) {
char *cur, *dirs[64];
int i, fd, fd_, argc;
+ struct timeval tv[2];
argc = 0;
cur = pathname;
@@ -284,6 +286,12 @@
fprintf(stderr, "openat() failed on %s: %s\n", dirs[i], strerror(errno));
break;
}
+
+ tv[0].tv_sec = (time_t)mtime;
+ tv[0].tv_usec = 0;
+ tv[1].tv_sec = (time_t)mtime;
+ tv[1].tv_usec = 0;
+ futimes(fd, &tv[0]);
}
if(fd >= 0) close(fd);
if(i != argc) return -1;
@@ -321,7 +329,7 @@
else if(st.st_size != size) {
fetch = TRUE;
}
- else if(st.st_mtime < mtime) {
+ else if(st.st_mtime != mtime) {
fetch = TRUE;
}
}
@@ -414,21 +422,46 @@
}
else if(!strcmp(args[0], "close")) {
char *pathname = args[1];
+ int long long mtime = atoll(args[2]);
+ FILE *f;
+
+ f = g_hash_table_lookup(conn->openfiles, pathname);
+ if(f) {
+ struct timeval tv[2];
+ tv[0].tv_sec = (time_t)mtime;
+ tv[0].tv_usec = 0;
+ tv[1].tv_sec = (time_t)mtime;
+ tv[1].tv_usec = 0;
+
+ futimes(fileno(f), &tv[0]);
+ }
g_hash_table_remove(conn->openfiles, pathname);
}
else if(!strcmp(args[0], "mkdir")) {
char *path = args[1];
- vhffsfssync_mkdir(path, 0755);
+ int long long mtime = atoll(args[2]);
+
+ vhffsfssync_mkdir(path, 0755, mtime);
}
else if(!strcmp(args[0], "symlink")) {
char *from = args[1];
char *to = args[2];
+ int long long mtime = atoll(args[3]);
struct stat st;
+
if(! lstat(from, &st) ) {
vhffsfssync_remove(from);
}
if( symlink(to, from) ) {
fprintf(stderr, "symlink() failed on %s -> %s: %s\n", from, to, strerror(errno));
+ } else {
+ struct timeval tv[2];
+ tv[0].tv_sec = (time_t)mtime;
+ tv[0].tv_usec = 0;
+ tv[1].tv_sec = (time_t)mtime;
+ tv[1].tv_usec = 0;
+
+ lutimes(from, &tv[0]);
}
}
else if(!strcmp(args[0], "move")) {
@@ -483,10 +516,12 @@
}
else if(!strcmp(args[0], "ls")) {
char *root, *root_;
+ int long long dirmtime = atoll(args[2]);
+
root = args[1];
root_ = strdup(root);
- if(! vhffsfssync_mkdir(root, 0755) ) {
+ if(! vhffsfssync_mkdir(root, 0755, dirmtime) ) {
int i;
GHashTable *filesindex;
DIR *d;
@@ -495,7 +530,7 @@
filesindex = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
// check each file
- for( i = 2 ; i < argc ; i+=4 ) {
+ for( i = 3 ; i < argc ; i+=4 ) {
char *path;
g_hash_table_insert(filesindex, args[i], args[i]);