[vhffs-dev] [1535] completed mtime support, now updating parent mtime

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1535
Author:   gradator
Date:     2010-01-10 01:59:02 +0100 (Sun, 10 Jan 2010)
Log Message:
-----------
completed mtime support, now updating parent mtime

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 22:36:16 UTC (rev 1534)
+++ trunk/vhffs-fssync/vhffsfssync_master.c	2010-01-10 00:59:02 UTC (rev 1535)
@@ -212,6 +212,7 @@
 int vhffsfssync_net_file_close(vhffsfssync_conn *conn, vhffsfssync_net_file *file);
 int vhffsfssync_net_remove_file(vhffsfssync_conn *conn, char *pathname);
 void vhffsfssync_net_broadcast_file(char *pathname);
+char *vhffsfssync_net_parent_mtime(char *pathname);
 int vhffsfssync_net_send(vhffsfssync_conn *conn);
 int vhffsfssync_net_recv_event(vhffsfssync_conn *conn, char *event);
 int vhffsfssync_net_parse(vhffsfssync_conn *conn);
@@ -418,6 +419,7 @@
 	vhffsfssync_net_remove_file(conn, pathname);
 	//printf("%d SENDING FILE %s\n", conn->fd, pathname);
 	vhffsfssync_net_send_event(conn, g_strdup_printf("open%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+	vhffsfssync_net_send_event(conn, vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 
 	// the size of the file is the priority (small files are sent with more priority)
 	// but don't set the priority too low, low value can be used for anything else
@@ -560,6 +562,29 @@
 }
 
 
+char *vhffsfssync_net_parent_mtime(char *pathname)  {
+	char *cur;
+	struct stat st;
+	char *ret;
+	st.st_mtime = 0;
+
+	for( cur = pathname+strlen(pathname) ; *cur != '/' ; cur-- );
+	*cur = '\0';
+
+	if( lstat(pathname, &st) )  {
+		if(errno == ENOENT) {
+			// file already disappeared (common for temporary files)
+		} else {
+			fprintf(stderr, "cannot lstat() '%s': %s\n", pathname, strerror(errno));
+		}
+	}
+
+	ret = g_strdup_printf("mtime%c%s%c%ld%c", '\0', pathname, '\0', st.st_mtime, '\0');
+	*cur = '/';
+	return ret;
+}
+
+
 int vhffsfssync_net_send(vhffsfssync_conn *conn)  {
 	GList *msgs;
 	gboolean full = FALSE;
@@ -820,6 +845,7 @@
 			}
 			else if( S_ISDIR(st.st_mode) )  {
 				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);
+				vhffsfssync_net_send_event(conn, vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 			}
 			else if( S_ISLNK(st.st_mode) )  {
 				char *linkto;
@@ -827,6 +853,7 @@
 				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%ld%c", '\0', pathname, '\0', linkto, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+					vhffsfssync_net_send_event(conn, vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 				}
 				free(linkto);
 			}
@@ -1284,6 +1311,7 @@
 		conns = g_list_next(conns);
 		vhffsfssync_net_remove_file(conn, pathname);
 		vhffsfssync_net_send_event(conn, g_strdup_printf("remove%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+		vhffsfssync_net_send_event(conn, vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 	}
 	return 0;
 }
@@ -1300,6 +1328,7 @@
 #endif
 			if(!st.st_size)  {
 				vhffsfssync_net_broadcast_event( g_strdup_printf("create%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+				vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 			}
 			else {
 				vhffsfssync_net_broadcast_file(pathname);
@@ -1312,6 +1341,7 @@
 #endif
 			vhffsfssync_add_watch(inotifyfd, pathname, VHFFSFSSYNC_WATCH_MASK);
 			vhffsfssync_net_broadcast_event( g_strdup_printf("mkdir%c%s%c%ld%c", '\0', pathname, '\0', st.st_mtime, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+			vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_mtime(pathname) , 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 );
@@ -1328,6 +1358,7 @@
 				printf("==> SYMLINK %s -> %s\n", pathname, linkto);
 #endif
 				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);
+				vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 			}
 			free(linkto);
 			if(ret < 0) {
@@ -1469,6 +1500,8 @@
 			if( vhffsfssync_cookie.isdir )  {
 				vhffsfssync_modify_watch(inotifyfd, vhffsfssync_cookie.from, pathname);
 				vhffsfssync_net_broadcast_event( g_strdup_printf("move%c%s%c%s%c", '\0', vhffsfssync_cookie.from, '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+				vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_mtime(vhffsfssync_cookie.from) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+				vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_mtime(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 			}
 			else {
 				vhffsfssync_manage_event_remove(inotifyfd, vhffsfssync_cookie.from);

Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c	2010-01-09 22:36:16 UTC (rev 1534)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c	2010-01-10 00:59:02 UTC (rev 1535)
@@ -264,7 +264,6 @@
 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;
@@ -287,17 +286,20 @@
 			fprintf(stderr, "openat() failed on %s: %s\n", dirs[i], strerror(errno));
 			break;
 		}
-
-		if(mtime) {
+	}
+	if(fd >= 0) {
+		if(mtime && i == argc) {
+			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(fd, &tv[0]);
 		}
+		close(fd);
 	}
-	if(fd >= 0) close(fd);
 	if(i != argc) return -1;
+
 	return 0;
 }
 #endif
@@ -524,6 +526,18 @@
 			conn->chunk_file = NULL;
 		}
 	}
+	else if(!strcmp(args[0], "mtime")) {
+		char *pathname = args[1];
+		int long long mtime = atoll(args[2]);
+		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(pathname, &tv[0]);
+	}
 	else if(!strcmp(args[0], "ls")) {
 		char *root, *root_;
 
@@ -637,6 +651,8 @@
 		ssize_t size = atol(args[3]);
 		conn->chunk_stilltoread = size;
 	}
+	else if(!strcmp(args[0], "mtime")) {
+	}
 	else if(!strcmp(args[0], "ls")) {
 		char *root, *root_;
 		struct stat st;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/