This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fun with cp -R error when both foo and foo.exe exist


On 10/9/18 11:21 AM, Dan Kegel wrote:
On Tue, Oct 9, 2018 at 5:03 AM Eric Blake <eblake@redhat.com> wrote:
whether someone patches the cygwin dll or cp, it seems like some rather
hairy code for what is normally a rare corner case, so it probably won't
happen unless someone actually contributes a patch.

Right.  Here's a completely untested guess patch:

--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1363,7 +1363,15 @@ open (const char *unix_path, int flags, ...)
           opt |= PC_CTTY;
         }

-      if (!(fh = build_fh_name (unix_path, opt, stat_suffixes)))
+      suffix_info *suffices = stat_suffixes;

suffices is a completely different word; did you mean suffixes?

+      if ((opt & (O_WRONLY|O_BINARY)) == (O_WRONLY|O_BINARY))

O_WRONLY need not be a bitmask; it's better to use O_ACCMODE for the bitmask, as in
 opt & (O_ACCMODE|O_BINARY) == O_WRONLY|O_BINARY

+        {
+         /* Hack so 'cp foo bar' doesn't abort with
+             'cp: cannot create regular file bar: File exists'
+            if bar.exe already exists  */
+       suffices = NULL;
+       }
+      if (!(fh = build_fh_name (unix_path, opt, suffices)))

So, with mistakes corrected, your hack is that cygwin doing auto-suffix probing should be suppressed in the case of opening a file O_WRONLY? Why does O_BINARY have to fit in the equation?

         __leave;                /* errno already set */
        if ((flags & O_NOFOLLOW) && fh->issymlink ())
         {

Feel free to throw rotten fruit :-)


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]