Re: backup deleting old files
- From: Robert Mibus <mibus bigpond com>
- To: Eskil Heyn Olsen <eskil eazel com>
- Cc: Vadim Strizhevsky <vadim optonline net>,mibus <mibus telstra com>, Chris Green <cmg dok org>,gnome-pilot-list <gnome-pilot-list gnome org>
- Subject: Re: backup deleting old files
- Date: Tue, 18 Jul 2000 17:01:03 +0930
On Tue, Jul 18, 2000 at 03:28:21PM +0930, Robert Mibus wrote:
> On Mon, Jul 17, 2000 at 05:13:48PM -0700, Eskil Heyn Olsen wrote:
> ok then, ive just looked and it shouldnt be too hard.
> ive got plenty of time this week (and its not exactly a lot of code) so it
> should be done soon.
ok, it was less than i expected :)
it includes the sprintf change as req'd. the only thing it doesnt do is put
an option in the capplet, someone else will have to do that, my gtk code
sucks.
the max number of backups should be limited to 100 or less. (who the hell
needs more ?? :-).
(diff -u against CVS)
mibus
--
Robert Mibus <mibus@bigpond.com>
./configure --prefix=/dev/mocha --enable-caffein --enable-double-shot
--- backup-conduit-control-applet.c.orig Tue Jul 18 16:35:03 2000
+++ backup-conduit-control-applet.c Tue Jul 18 15:31:28 2000
@@ -72,6 +72,8 @@
(*c)->backup_dir = gnome_config_get_string("backup_dir");
(*c)->updated_only = gnome_config_get_bool("updated_only=TRUE");
(*c)->remove_deleted = gnome_config_get_bool("remove_deleted=FALSE");
+ (*c)->no_of_backups = gnome_config_get_int("no_of_backups=0");
+
exclude = gnome_config_get_string("exclude_files");
if(exclude != NULL) {
(*c)->exclude_files = NULL;
@@ -133,6 +135,7 @@
gnome_config_set_string("backup_dir",c->backup_dir);
gnome_config_set_bool("updated_only",c->updated_only);
gnome_config_set_bool("remove_deleted",c->remove_deleted);
+ gnome_config_set_int("no_of_backups",c->no_of_backups);
gnome_config_set_string("exclude_files",exc);
gnome_config_pop_prefix();
gnome_config_sync();
@@ -155,6 +158,7 @@
d->exclude_files = g_list_copy(c->exclude_files);
if(d->files_in_backup) g_list_free(d->files_in_backup);
d->files_in_backup = g_list_copy(c->files_in_backup);
+ d->no_of_backups = c->no_of_backups;
}
static ConduitCfg*
--- backup_conduit.c.orig Thu Jul 6 12:25:45 2000
+++ backup_conduit.c Tue Jul 18 16:37:20 2000
@@ -44,6 +44,7 @@
(*c)->backup_dir = gnome_config_get_string("backup_dir");
(*c)->updated_only = gnome_config_get_bool("updated_only=TRUE");
(*c)->remove_deleted = gnome_config_get_bool("remove_deleted=FALSE");
+ (*c)->no_of_backups = gnome_config_get_int("no_of_backups=0");
(*c)->exclude_files = NULL;
gnome_config_get_vector("exclude_files",
@@ -73,13 +74,12 @@
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);
+ if (*(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);
@@ -92,6 +92,7 @@
destroy_configuration(ConduitCfg **c)
{
GList *temp_list;
+ gchar *backup_name;
g_return_if_fail(c!=NULL);
g_return_if_fail(*c!=NULL);
@@ -101,13 +102,22 @@
temp_list = (*c)->files_in_backup;
while (temp_list) {
if (temp_list->data) {
+ backup_name = g_malloc (strlen (temp_list->data) + 6);
+ strcpy (backup_name, temp_list->data);
+ sprintf (strrchr (backup_name, '/'), "/del");
+ mkdir (backup_name, (mode_t)0755);
+ strcat (backup_name, strrchr (temp_list->data, '/'));
+
g_message ("Deleting %s", (char *) temp_list->data);
-/*DANGER WILL ROBINSON*/ unlink (temp_list->data);
+ g_message (" (to %s)", backup_name);
+ if (rename (temp_list->data, backup_name) != 0)
+ g_message ("Error renaming :(");
+ g_free (backup_name);
g_free (temp_list->data);
}
temp_list = temp_list->next;
}
- g_list_free((*c)->files_in_backup);
+ g_list_free((*c)->files_in_backup);
}
g_list_foreach((*c)->exclude_files,(GFunc)g_free,NULL);
@@ -168,6 +178,8 @@
struct stat statb;
struct utimbuf times;
GList *iterator;
+ int i;
+ char *backup_name_from=NULL, *backup_name_to=NULL;
g_return_val_if_fail (conduit != NULL, -1);
g_return_val_if_fail (dbinfo != NULL, -1);
@@ -229,6 +241,30 @@
gnome_pilot_conduit_message(GNOME_PILOT_CONDUIT(conduit),
_("Making backup of %s"),PI_DBINFO (dbinfo)->name);
+ /* create backup of old db*/
+ for (i = cfg->no_of_backups - 1;i >= 0; i--) {
+ if (i) {
+ backup_name_from = g_malloc (strlen (name) + 6);
+ strcpy (backup_name_from, name);
+ sprintf (strrchr (backup_name_from, '/'), "/%i/%s", i - 1, strrchr (name, '/') + 1);
+ } else
+ backup_name_from = strdup (name);
+
+ backup_name_to = g_malloc (strlen (name) + 6);
+ strcpy (backup_name_to, name);
+ sprintf (strrchr (backup_name_to, '/'), "/%i", i);
+ mkdir (backup_name_to, (mode_t)0755);
+ strcat (backup_name_to, strrchr (name, '/'));
+
+ g_message ("Moving backup from %s to %s", backup_name_from, backup_name_to);
+ if (rename (backup_name_from, backup_name_to) == -1)
+ g_message (" (failed)");
+
+ free (backup_name_from);
+ free (backup_name_to);
+ }
+
+ /* backup new db */
f = pi_file_create (name, PI_DBINFO (dbinfo));
if(f==0) {
g_warning(_("Could not create backup file %s"),name);
--- backup_conduit.h.orig Tue Jul 18 16:34:41 2000
+++ backup_conduit.h Tue Jul 18 15:31:28 2000
@@ -12,6 +12,7 @@
GList *exclude_files;
GList *files_in_backup; /* contains the file in backup, any entries when
destroy is called are considered deleted on PDA */
+ int no_of_backups; /* # of backups to keep after the main one */
gboolean remove_deleted;
gboolean updated_only;
guint32 pilotId;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]