rpms/patch/devel patch-posix-backup.patch, NONE, 1.1 patch.spec, 1.33, 1.34

Tim Waugh (twaugh) fedora-extras-commits at redhat.com
Mon Jun 16 11:01:05 UTC 2008


Author: twaugh

Update of /cvs/pkgs/rpms/patch/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv2947

Modified Files:
	patch.spec 
Added Files:
	patch-posix-backup.patch 
Log Message:
* Mon Jun 16 2008 Tim Waugh <twaugh at redhat.com> 2.5.4-34
- Only write simple backups for each file once during a run
  (bug #234822).


patch-posix-backup.patch:

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


Index: patch.spec
===================================================================
RCS file: /cvs/pkgs/rpms/patch/devel/patch.spec,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- patch.spec	12 Jun 2008 10:22:54 -0000	1.33
+++ patch.spec	16 Jun 2008 11:00:21 -0000	1.34
@@ -1,7 +1,7 @@
 Summary: The GNU patch command, for modifying/upgrading files
 Name: patch
 Version: 2.5.4
-Release: 33%{?dist}
+Release: 34%{?dist}
 License: GPLv2+
 URL: http://www.gnu.org/software/patch/patch.html
 Group: Development/Tools
@@ -15,6 +15,7 @@
 Patch7: patch-parse.patch
 Patch8: patch-allow-spaces.patch
 Patch9: patch-selinux.patch
+Patch10: patch-posix-backup.patch
 Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildRequires: libselinux-devel
@@ -40,6 +41,7 @@
 %patch7 -p1 -b .parse
 %patch8 -p1 -b .allow-spaces
 %patch9 -p1 -b .selinux
+%patch10 -p1 -b .posix-backup
 
 %build
 CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE"
@@ -66,6 +68,10 @@
 %{_mandir}/*/*
 
 %changelog
+* Mon Jun 16 2008 Tim Waugh <twaugh at redhat.com> 2.5.4-34
+- Only write simple backups for each file once during a run
+  (bug #234822).
+
 * Thu Jun 12 2008 Tim Waugh <twaugh at redhat.com> 2.5.4-33
 - Fix selinux patch and apply it.  Build requires libselinux-devel.
 




More information about the fedora-extras-commits mailing list