public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin@cygwin.com
Subject: Re: Deleting a directory with the same name as a shortcut deletes everything in CWD
Date: Mon, 8 Aug 2022 19:29:21 -0400	[thread overview]
Message-ID: <bf4b113b-f22e-5a55-9da7-27ff5b16302b@cornell.edu> (raw)
In-Reply-To: <003884bf-bb7a-984a-668a-21221f142638@t-online.de>

On 8/8/2022 7:56 AM, Christian Franke wrote:
> Testcase:
> 
> $ ls -a
> .  ..
> 
> $ touch link.lnk file.txt
> 
> $ ls -a
> .  ..  file.txt  link.lnk
> 
> $ stat -c %F link.lnk
> regular empty file
> 
> $ stat -c %F link
> directory

This happens because symlink_info::check returns -1 instead of 0 when called on 
"link".  The main loop over suffixes finds and rejects link.lnk but then leaves 
"res" as -1 when it continues looping.  The following patch fixes the problem:

--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3422,6 +3422,7 @@ restart:
         {
           fileattr = INVALID_FILE_ATTRIBUTES;
           set_error (ENOENT);
+         res = 0;
           continue;
         }

It's possible that a better fix would be to set res = 0 at the beginning of each 
iteration of the loop, but I'll have to study the code more carefully before I'm 
sure of that.  Also, the comment preceding symlink_info::check needs to be fixed 
to correctly indicate what a negative return value means.  I'll look at all this 
more carefully tomorrow if no one beats me to it.

Ken

  reply	other threads:[~2022-08-08 23:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 10:50 Oskar Skog
2022-08-08 11:56 ` Christian Franke
2022-08-08 23:29   ` Ken Brown [this message]
2022-08-09 19:52     ` Ken Brown
2022-08-09 20:01       ` Oskar Skog
2022-08-09 20:11         ` Ken Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf4b113b-f22e-5a55-9da7-27ff5b16302b@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).