quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] why create new backup file with no permission?


From: Yasushi SHOJI
Subject: [Quilt-dev] why create new backup file with no permission?
Date: Thu, 19 Aug 2004 20:45:22 +0900
User-agent: User-Agent: Wanderlust/2.10.1

Hi,

is there any reason to create a new backup file of missing file?

current quilt does:

$ quilt new foo.diff
Patch foo.diff is now on top
$ quilt add foo.txt
File foo.txt added to patch foo.diff
$ ls -l .pc/foo.diff
total 0
----------  1 yashi yashi 0 Aug 19 20:35 foo.txt


comments in backup-files.c reads: because gnu patch is doing as
well. quick test on my local machine didn't show that gnu patch create
new file without permissions.

anyway, would you apply the attached patch if there is no reason for
the current behaviour?

with attached patch:

$ quilt new foo.diff
Patch foo.diff is now on top
$ quilt add foo.txt
File foo.txt added to patch foo.diff
$ ls -l .pc/foo.diff
total 0
-rw-------  1 yashi yashi 0 Aug 19 20:38 foo.txt

best,
--
              yashi

* added: create_file(), shamelessly taken from gnu patch 2.5.9
* fixed: create backup for missing file with at least rw permission
for owner

Index: backup-files.c
===================================================================
RCS file: /cvsroot/quilt/quilt/lib/backup-files.c,v
retrieving revision 1.9
diff -u -r1.9 backup-files.c
--- backup-files.c      6 Jun 2004 00:20:07 -0000       1.9
+++ backup-files.c      19 Aug 2004 11:41:07 -0000
@@ -212,6 +212,21 @@
                return 0;
 }
 
+/* Create FILE with OPEN_FLAGS, and with MODE adjusted so that
+   we can read and write the file and that the file is not executable.
+   Return the file descriptor. */
+int
+create_file (char const *file, int open_flags, mode_t mode)
+{
+       int fd;
+       mode |= S_IRUSR | S_IWUSR;
+       mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH);
+       if (! (O_CREAT && O_TRUNC))
+               close (creat (file, mode));
+       fd = open (file, O_CREAT | O_TRUNC | open_flags, mode);
+       return fd;
+}
+
 int
 process_file(const char *file)
 {
@@ -231,8 +246,8 @@
 
                        if (!opt_silent)
                                printf("New file %s\n", file);
-                       /* GNU patch creates new files with mode==0. */
-                       if ((fd = creat(backup, 0)) == -1) {
+                        /* nothing to write for now, use read only */
+                       if ((fd = create_file(backup, O_RDONLY, 0)) == -1) {
                                perror(backup);
                                return 1;
                        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]