On Sun, 20 Mar 2022 19:12:13 +0100 Oswald Buddenhagen via mc-devel 
<mc-devel@gnome.org> wrote:
> On Sun, Mar 20, 2022 at 06:59:32PM +0300, Andrew Borodin wrote:
> >On Sun, 20 Mar 2022 15:22:14 +0100 Oswald Buddenhagen via mc-devel 
> ><mc-devel@gnome.org>
> > wrote:
> >> `mc -P $file` doesn't work any more when the file already exists 
> >> (which is of course the case after file=`mktemp`).
> >
> >Indeed.
> >
> >A following patch is proposed:
> >
> >diff --git a/src/main.c b/src/main.c
> >index 3a33dfb59..a4910349a 100644
> >--- a/src/main.c
> >+++ b/src/main.c
> >@@ -492,6 +492,10 @@ main (int argc, char *argv[])
> > 
> >         last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | 
> > O_TRUNC | O_EXCL,
> >                            S_IRUSR | S_IWUSR);
> >+
> >+        if (last_wd_fd == -1 && errno == EEXIST)
> >+            last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_TRUNC, 
> >S_IRUSR | S_IWUSR);
> >+
> >         if (last_wd_fd != -1)
> >         {
> >             ssize_t ret1;
> >
> that seems overly complicated - why not just drop the O_EXCL? at least i 
> can't see an obvious
> reason for having it in the first place.

Ok.

> anyway, i wonder why i ran into this only recently, given that this behavior 
> is actually
> rather ancient. probably has something to do with me porting the wrapper 
> function from
> tempfile to mktemp (as debian started to complain about deprecation), though 
> the replacement
> itself couldn't have caused it.

mc-wrapper.sh doesn't create a file. It creates a file name only. then mc 
creates a file with
given file name, and everything works fine.

Wrapper patched to use mktemp creates a file, and mc tries to open an existing 
file and fails.
A workaround is to apply `mktemp -u` or even `mktemp -u -t`, but is it portable?

-- 
A.


_______________________________________________
mc-devel mailing list
https://mail.gnome.org/mailman/listinfo/mc-devel

Reply via email to