|
|
79f61f4 |
diff -up patch-2.5.4/util.c.posix-backup patch-2.5.4/util.c
|
|
|
79f61f4 |
--- patch-2.5.4/util.c.posix-backup 2008-06-16 10:22:52.000000000 +0100
|
|
|
79f61f4 |
+++ patch-2.5.4/util.c 2008-06-16 11:30:27.000000000 +0100
|
|
|
79f61f4 |
@@ -109,37 +109,40 @@ move_file (char const *from, int volatil
|
|
|
79f61f4 |
memory_fatal ();
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
|
|
|
79f61f4 |
- if (to_errno)
|
|
|
79f61f4 |
+ if (strcmp (bakname, "/dev/null") != 0)
|
|
|
79f61f4 |
{
|
|
|
79f61f4 |
- int fd;
|
|
|
79f61f4 |
+ if (to_errno)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ int fd;
|
|
|
79f61f4 |
|
|
|
79f61f4 |
- if (debug & 4)
|
|
|
79f61f4 |
- say ("Creating empty unreadable file %s\n", quotearg (bakname));
|
|
|
79f61f4 |
+ if (debug & 4)
|
|
|
79f61f4 |
+ say ("Creating empty unreadable file %s\n", quotearg (bakname));
|
|
|
79f61f4 |
|
|
|
79f61f4 |
- try_makedirs_errno = ENOENT;
|
|
|
79f61f4 |
- unlink (bakname);
|
|
|
79f61f4 |
- while ((fd = creat (bakname, 0)) < 0)
|
|
|
79f61f4 |
- {
|
|
|
79f61f4 |
- if (errno != try_makedirs_errno)
|
|
|
79f61f4 |
- pfatal ("Can't create file %s", quotearg (bakname));
|
|
|
79f61f4 |
- makedirs (bakname);
|
|
|
79f61f4 |
- try_makedirs_errno = 0;
|
|
|
79f61f4 |
+ try_makedirs_errno = ENOENT;
|
|
|
79f61f4 |
+ unlink (bakname);
|
|
|
79f61f4 |
+ while ((fd = creat (bakname, 0)) < 0)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ if (errno != try_makedirs_errno)
|
|
|
79f61f4 |
+ pfatal ("Can't create file %s", quotearg (bakname));
|
|
|
79f61f4 |
+ makedirs (bakname);
|
|
|
79f61f4 |
+ try_makedirs_errno = 0;
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ if (close (fd) != 0)
|
|
|
79f61f4 |
+ pfatal ("Can't close file %s", quotearg (bakname));
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
- if (close (fd) != 0)
|
|
|
79f61f4 |
- pfatal ("Can't close file %s", quotearg (bakname));
|
|
|
79f61f4 |
- }
|
|
|
79f61f4 |
- else
|
|
|
79f61f4 |
- {
|
|
|
79f61f4 |
- if (debug & 4)
|
|
|
79f61f4 |
- say ("Renaming file %s to %s\n",
|
|
|
79f61f4 |
- quotearg_n (0, to), quotearg_n (1, bakname));
|
|
|
79f61f4 |
- while (rename (to, bakname) != 0)
|
|
|
79f61f4 |
+ else
|
|
|
79f61f4 |
{
|
|
|
79f61f4 |
- if (errno != try_makedirs_errno)
|
|
|
79f61f4 |
- pfatal ("Can't rename file %s to %s",
|
|
|
79f61f4 |
- quotearg_n (0, to), quotearg_n (1, bakname));
|
|
|
79f61f4 |
- makedirs (bakname);
|
|
|
79f61f4 |
- try_makedirs_errno = 0;
|
|
|
79f61f4 |
+ if (debug & 4)
|
|
|
79f61f4 |
+ say ("Renaming file %s to %s\n",
|
|
|
79f61f4 |
+ quotearg_n (0, to), quotearg_n (1, bakname));
|
|
|
79f61f4 |
+ while (rename (to, bakname) != 0)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ if (errno != try_makedirs_errno)
|
|
|
79f61f4 |
+ pfatal ("Can't rename file %s to %s",
|
|
|
79f61f4 |
+ quotearg_n (0, to), quotearg_n (1, bakname));
|
|
|
79f61f4 |
+ makedirs (bakname);
|
|
|
79f61f4 |
+ try_makedirs_errno = 0;
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
|
|
|
79f61f4 |
diff -up patch-2.5.4/backupfile.c.posix-backup patch-2.5.4/backupfile.c
|
|
|
79f61f4 |
--- patch-2.5.4/backupfile.c.posix-backup 2008-06-16 11:27:55.000000000 +0100
|
|
|
79f61f4 |
+++ patch-2.5.4/backupfile.c 2008-06-16 11:44:05.000000000 +0100
|
|
|
79f61f4 |
@@ -23,6 +23,8 @@
|
|
|
79f61f4 |
# include <config.h>
|
|
|
79f61f4 |
#endif
|
|
|
79f61f4 |
|
|
|
79f61f4 |
+#define XTERN extern
|
|
|
79f61f4 |
+#include <common.h>
|
|
|
79f61f4 |
#include <argmatch.h>
|
|
|
79f61f4 |
#include <backupfile.h>
|
|
|
79f61f4 |
|
|
|
79f61f4 |
@@ -118,11 +120,15 @@ static int version_number PARAMS ((const
|
|
|
79f61f4 |
char *
|
|
|
79f61f4 |
find_backup_file_name (const char *file, enum backup_type backup_type)
|
|
|
79f61f4 |
{
|
|
|
79f61f4 |
+ static char **previous_files = NULL;
|
|
|
79f61f4 |
+ static int previous_files_allocated = 0;
|
|
|
79f61f4 |
+
|
|
|
79f61f4 |
size_t backup_suffix_size_max;
|
|
|
79f61f4 |
size_t file_len = strlen (file);
|
|
|
79f61f4 |
size_t numbered_suffix_size_max = INT_STRLEN_BOUND (int) + 4;
|
|
|
79f61f4 |
char *s;
|
|
|
79f61f4 |
const char *suffix = simple_backup_suffix;
|
|
|
79f61f4 |
+ int used_version = 0;
|
|
|
79f61f4 |
|
|
|
79f61f4 |
/* Allow room for simple or `.~N~' backups. */
|
|
|
79f61f4 |
backup_suffix_size_max = strlen (simple_backup_suffix) + 1;
|
|
|
79f61f4 |
@@ -147,12 +153,66 @@ find_backup_file_name (const char *file,
|
|
|
79f61f4 |
char *numbered_suffix = s + (file_len + backup_suffix_size_max);
|
|
|
79f61f4 |
sprintf (numbered_suffix, ".~%d~", highest_backup + 1);
|
|
|
79f61f4 |
suffix = numbered_suffix;
|
|
|
79f61f4 |
+ used_version = 1;
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
strcpy (s, file);
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
#endif /* HAVE_DIR */
|
|
|
79f61f4 |
|
|
|
79f61f4 |
- addext (s, suffix, '~');
|
|
|
79f61f4 |
+ if (used_version == 0)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ /* If we have already written a ".orig" backup file during
|
|
|
79f61f4 |
+ this run, don't overwrite it. */
|
|
|
79f61f4 |
+ if (previous_files_allocated != 0)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ int i;
|
|
|
79f61f4 |
+ for (i = 0; previous_files[i] != NULL; i++)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ if (!strcmp (previous_files[i], s))
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ strcpy (s, "/dev/null");
|
|
|
79f61f4 |
+ break;
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+
|
|
|
79f61f4 |
+ if (previous_files[i] == NULL)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ if (i == previous_files_allocated - 1)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ char **old_previous_files = previous_files;
|
|
|
79f61f4 |
+ previous_files = realloc (previous_files,
|
|
|
79f61f4 |
+ 2 * previous_files_allocated *
|
|
|
79f61f4 |
+ sizeof (const char *));
|
|
|
79f61f4 |
+ if (previous_files)
|
|
|
79f61f4 |
+ previous_files_allocated *= 2;
|
|
|
79f61f4 |
+ else
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ for (i = 0; old_previous_files[i] != NULL; i++)
|
|
|
79f61f4 |
+ free (old_previous_files[i]);
|
|
|
79f61f4 |
+ free (old_previous_files);
|
|
|
79f61f4 |
+ previous_files_allocated = 0;
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+
|
|
|
79f61f4 |
+ if (i < previous_files_allocated - 1)
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ previous_files[i] = strdup (s);
|
|
|
79f61f4 |
+ previous_files[i + 1] = NULL;
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ else
|
|
|
79f61f4 |
+ {
|
|
|
79f61f4 |
+ previous_files_allocated = 2;
|
|
|
79f61f4 |
+ previous_files = malloc (previous_files_allocated *
|
|
|
79f61f4 |
+ sizeof (const char *));
|
|
|
79f61f4 |
+ previous_files[0] = strdup (s);
|
|
|
79f61f4 |
+ previous_files[1] = NULL;
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+ }
|
|
|
79f61f4 |
+
|
|
|
79f61f4 |
+ if (strcmp (s, "/dev/null") != 0)
|
|
|
79f61f4 |
+ addext (s, suffix, '~');
|
|
|
79f61f4 |
}
|
|
|
79f61f4 |
return s;
|
|
|
79f61f4 |
}
|