[vhffs-dev] [1533] fixed a bug in the recovery process when a directory is replaced to a regular or symlink file

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


Revision: 1533
Author:   gradator
Date:     2010-01-09 21:48:49 +0100 (Sat, 09 Jan 2010)
Log Message:
-----------
fixed a bug in the recovery process when a directory is replaced to a regular or symlink file
improved recovery process

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 19:48:26 UTC (rev 1532)
+++ trunk/vhffs-fssync/vhffsfssync_master.c	2010-01-09 20:48:49 UTC (rev 1533)
@@ -1007,39 +1007,33 @@
 		d = opendir(pathname);
 		if(d) {
 			struct dirent *dir;
-			struct stat std;
 			GString *msg = g_string_sized_new(1024);
 
-			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');
+			g_string_append_printf(msg, "ls%c%s%c", '\0', pathname, '\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);
+					struct stat st;
 
-					if(dir->d_type == DT_DIR)  {
-						// register a new directory
-						ldirs = g_list_append(ldirs,  path);
-						g_string_append_printf(msg, "%s%cdir%c0%c0%c", dir->d_name, '\0', '\0', '\0', '\0');
-					}
-					else {
-						// file or link
-						struct stat st;
-						if(! lstat(path, &st) )  {
-							if( S_ISREG(st.st_mode) )  {
-								g_string_append_printf(msg, "%s%cfile%c%lld%c%ld%c", dir->d_name, '\0', '\0', (long long int)st.st_size, '\0', st.st_mtime, '\0');
-							}
-							else if( S_ISLNK(st.st_mode) )  {
-								g_string_append_printf(msg, "%s%clink%c%lld%c%ld%c", dir->d_name, '\0', '\0', (long long int)st.st_size, '\0', st.st_mtime, '\0');
-							}
-							/* we don't need other file types (chr, block, fifo, socket, ...) */
+					if(! lstat(path, &st) )  {
+						if( S_ISDIR(st.st_mode) )  {
+							// register a new directory
+							ldirs = g_list_append(ldirs, g_strdup(path));
+							g_string_append_printf(msg, "%s%cdir%c0%c%ld%c", dir->d_name, '\0', '\0', '\0', st.st_mtime, '\0');
 						}
-						else {
-							fprintf(stderr, "cannot lstat() '%s': %s\n", pathname, strerror(errno));
+						else if( S_ISREG(st.st_mode) )  {
+							g_string_append_printf(msg, "%s%cfile%c%lld%c%ld%c", dir->d_name, '\0', '\0', (long long int)st.st_size, '\0', st.st_mtime, '\0');
 						}
-						free(path);
+						else if( S_ISLNK(st.st_mode) )  {
+							g_string_append_printf(msg, "%s%clink%c%lld%c%ld%c", dir->d_name, '\0', '\0', (long long int)st.st_size, '\0', st.st_mtime, '\0');
+						}
+						/* we don't need other file types (chr, block, fifo, socket, ...) */
 					}
+					else {
+						fprintf(stderr, "cannot lstat() '%s': %s\n", path, strerror(errno));
+					}
+					free(path);
 				}
 			}
 			closedir(d);

Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c	2010-01-09 19:48:26 UTC (rev 1532)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c	2010-01-09 20:48:49 UTC (rev 1533)
@@ -287,11 +287,13 @@
 			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(mtime) {
+			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;
@@ -308,31 +310,33 @@
 
 	// file or link
 	if(! lstat(path, &st) )  {
-		if(! S_ISDIR(st.st_mode) ) {
-			char *type_ = "unknown";
+		char *type_ = "unknown";
 
-			if( S_ISREG(st.st_mode) )  {
-				type_ = "file";
-			}
+		if( S_ISDIR(st.st_mode) )  {
+			type_ = "dir";
+		}
 
-			else if( S_ISLNK(st.st_mode) )  {
-				type_ = "link";
-			}
-			/* we don't need other file types (chr, block, fifo, socket, ...) */
+		else if( S_ISREG(st.st_mode) )  {
+			type_ = "file";
+		}
 
-			if(strcmp(type, type_)) {
+		else if( S_ISLNK(st.st_mode) )  {
+			type_ = "link";
+		}
+		/* we don't need other file types (chr, block, fifo, socket, ...) */
+
+		if(strcmp(type, type_)) {
 #ifndef CHECK
-				vhffsfssync_remove(path);
+			vhffsfssync_remove(path);
 #endif
-				fetch = TRUE;
-			}
-			else if(st.st_size != size) {
-				fetch = TRUE;
-			}
-			else if(st.st_mtime != mtime) {
-				fetch = TRUE;
-			}
+			fetch = TRUE;
 		}
+		else if(!S_ISDIR(st.st_mode) && st.st_size != size) {
+			fetch = TRUE;
+		}
+		else if(st.st_mtime != mtime) {
+			fetch = TRUE;
+		}
 	}
 	else {
 		if(errno == ENOENT) {
@@ -516,12 +520,11 @@
 	}
 	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, dirmtime) ) {
+		if(! vhffsfssync_mkdir(root, 0755, 0) ) {
 			int i;
 			GHashTable *filesindex;
 			DIR *d;
@@ -530,7 +533,7 @@
 			filesindex = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
 
 			// check each file
-			for( i = 3 ; i < argc ; i+=4 ) {
+			for( i = 2 ; i < argc ; i+=4 ) {
 				char *path;
 				g_hash_table_insert(filesindex, args[i], args[i]);
 
@@ -647,7 +650,7 @@
 			filesindex = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
 
 			// check each file
-			for( i = 3 ; i < argc ; i+=4 ) {
+			for( i = 2 ; i < argc ; i+=4 ) {
 				char *path;
 				g_hash_table_insert(filesindex, args[i], args[i]);
 


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