quilt-dev
[Top][All Lists]
Advanced

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

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


From: Andreas Gruenbacher
Subject: Re: [Quilt-dev] why create new backup file with no permission?
Date: Thu, 19 Aug 2004 14:18:18 +0200

On Thu, 2004-08-19 at 13:45, Yasushi SHOJI wrote:
> 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

Yes, this is the way how quilt remembers that the file foo.txt was
created (and will be removed when doing a ``quilt pop''). ``Quilt push''
uses patch to apply the patches and create backup files, so it makes
sense to behave the same way as patch does.

I don't know why patch tries to tell a file create from patching a
zero-length file, but it does.

> 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.

Do this to verify:

$ quilt refresh
Refreshed patch foo.diff
$ quilt pop
Removing patch foo.diff
Removing foo.txt

No patches applied
$ patch --backup --prefix=backup/ < patches/foo.diff
patching file foo.txt
$ ls -l backup
----------  1 [...] foo.txt

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

There is a reason for the current behavior.

> 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);

Why should we remove execute flags? I really don't want to do that: we
may well be patching a script, for example.

> +     if (! (O_CREAT && O_TRUNC))

The above test makes no sense to me.

> +             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;
>                       }

Cheers,
-- 
Andreas Gruenbacher <address@hidden>
SUSE Labs, SUSE LINUX AG






reply via email to

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