backup deleting old files



the backup conduit not deleting files that had been deleted on the palm was
one of the most annoying things for me (the toggle option did nothing).

try this patch (diff'ed against gnome-pilot-1.0.52's backup_conduit.c). i
would appreciate comments, queries, flame, etc :)

if you don't want to trust your backups to it, comment out the unlink()
line. if you want to see the messages, go to a console, type

  killall pilot_applet
  killall gpilotd
  pilot_applet

hopefully the patch is good enough for you guys & gets committed. (as
opposed to me getting committed :)

(the patch is also @ http://users.bigpond.com/mibus/gnome-pilot.patch incase
the attachment doesnt 'stick' to this message.)
-- 
Robert Mibus <mibus@bigpond.com>
"For a list of the ways which technology has failed to improve our quality
of life, press 3."
--- backup_conduit.c.orig	Tue Mar 21 01:20:29 2000
+++ backup_conduit.c	Sun Jun 18 19:19:29 2000
@@ -16,6 +16,7 @@
 #include <pwd.h>
 #include <signal.h>
 #include <errno.h>
+#include <dirent.h>
 
 #include <gpilotd/gnome-pilot-conduit-backup.h>
 #include "backup_conduit.h"
@@ -26,10 +27,13 @@
 static void 
 load_configuration(ConduitCfg **c,guint32 pilotId) 
 {
+	gchar *temp_name;
 	gchar *prefix;
 	gchar **exclude_files;
 	gint num_of_exclude_files = 0;
 	guint i;
+	DIR *dir;
+	struct dirent *entry;
 
 	*c = g_new0(ConduitCfg,1);
 	(*c)->child = -1;
@@ -55,7 +59,6 @@
 	}
 	gnome_config_pop_prefix();
 	
-	(*c)->files_in_backup = NULL;
 	if((*c)->backup_dir != NULL && 
 	   mkdir((*c)->backup_dir,(mode_t)0755) < 0) { /* Wow, I never though I would
 							  use octal in C :) */
@@ -65,6 +68,22 @@
 			*/
 		}
 	}    
+
+        (*c)->files_in_backup = g_list_alloc();
+        dir = opendir ((*c)->backup_dir);
+	while ((entry = readdir (dir))) {
+		if (entry->d_name)
+			if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
+				if ((*c)->backup_dir[strlen((*c)->backup_dir)-1] == '/')
+					temp_name = g_strdup_printf ("%s%s", ((*c)->backup_dir), entry->d_name);
+				else
+					temp_name = g_strdup_printf ("%s/%s", ((*c)->backup_dir), entry->d_name);
+
+				g_list_append ((*c)->files_in_backup, temp_name);
+			}
+	}
+	closedir (dir);
+
 	(*c)->pilotId = pilotId;
 	g_free(prefix);
 }
@@ -72,13 +91,25 @@
 static void 
 destroy_configuration(ConduitCfg **c) 
 {
+	GList *temp_list;
+
 	g_return_if_fail(c!=NULL);
 	g_return_if_fail(*c!=NULL);
 
 	if((*c)->remove_deleted) {
-		g_list_free((*c)->files_in_backup);
+		g_message ("Checking what to delete...");
+		temp_list = (*c)->files_in_backup;
+		while (temp_list) {
+			if (temp_list->data) {
+				g_message ("Deleting %s", (char *) temp_list->data);
+/*DANGER WILL ROBINSON*/	unlink (temp_list->data);
+				g_free (temp_list->data);
+			}
+			temp_list = temp_list->next;
+		}
+	g_list_free((*c)->files_in_backup);
 	}
-	
+
 	g_list_foreach((*c)->exclude_files,(GFunc)g_free,NULL);
 	g_list_free((*c)->exclude_files);
 	g_free((*c)->backup_dir);
@@ -169,14 +200,13 @@
 
 	if (cfg->remove_deleted) {
 		GList *link;
-
-		link = g_list_find_custom (cfg->files_in_backup,
-					   name,
-					   (GCompareFunc) g_strcasecmp);
-		cfg->files_in_backup =
-			g_list_remove_link (cfg->files_in_backup,
-					    link);
+		link = cfg->files_in_backup;
+		while (link) {
+			if (link->data) if (strcasecmp(link->data, name) == 0) g_list_remove_link (cfg->files_in_backup, link);
+			link=link->next;
+		}
 	}
+
 	if (cfg->updated_only) {
 		if (stat (name, &statb) == 0) {
 			if (PI_DBINFO (dbinfo)->modifyDate == statb.st_mtime) {

PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]