public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: path_conv: add PC_SYM_NOFOLLOW_DIR flag Date: Tue, 28 Jan 2020 17:02:00 -0000 [thread overview] Message-ID: <20200128170222.56830.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=26425142ce9e8981e9f97e7d50e632c4f9ee9a03 commit 26425142ce9e8981e9f97e7d50e632c4f9ee9a03 Author: Corinna Vinschen <corinna@vinschen.de> Date: Tue Jan 28 17:40:40 2020 +0100 Cygwin: path_conv: add PC_SYM_NOFOLLOW_DIR flag Usually a trailing slash requires to follow an existing symlink, even with PC_SYM_NOFOLLOW. The reason is that "foo/" is equivalent to "foo/." so the symlink is in fact not the last path component, "." is. This is default for almost all scenarios. PC_SYM_NOFOLLOW_DIR now allows the caller to request not to follow the symlink even if a trailing slash is given. This can be used in callers to perform certain functions Linux-compatible. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/path.cc | 27 ++++++++++++++++++++------- winsup/cygwin/path.h | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index a002702..5ebbddf 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -1022,20 +1022,33 @@ path_conv::check (const char *src, unsigned opt, these operations again on the newly derived path. */ else if (symlen > 0) { - if (component == 0 && !need_directory + if (component == 0 && (!(opt & PC_SYM_FOLLOW) || (is_known_reparse_point () && (opt & PC_SYM_NOFOLLOW_REP)))) { - /* last component of path is a symlink. */ - set_symlink (symlen); - if (opt & PC_SYM_CONTENTS) + /* Usually a trailing slash requires to follow a symlink, + even with PC_SYM_NOFOLLOW. The reason is that "foo/" + is equivalent to "foo/." so the symlink is in fact not + the last path component. + + PC_SYM_NOFOLLOW_DIR is used to indicate that the + last path component is the target symlink and the + trailing slash is supposed to be ignored. */ + if (!need_directory || (opt & PC_SYM_NOFOLLOW_DIR)) { - strcpy (THIS_path, sym.contents); + /* last component of path is a symlink. */ + set_symlink (symlen); + /* make sure not to set errno to ENOTDIR. */ + need_directory = 0; + if (opt & PC_SYM_CONTENTS) + { + strcpy (THIS_path, sym.contents); + goto out; + } + add_ext = true; goto out; } - add_ext = true; - goto out; } /* Following a symlink we can't trust the collected filesystem information any longer. */ diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 72f4bda..7b89b03 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -59,6 +59,7 @@ enum pathconv_arg PC_SYM_NOFOLLOW_PROCFD = _BIT (11), /* allow /proc/PID/fd redirection */ PC_KEEP_HANDLE = _BIT (12), /* keep handle for later stat calls */ PC_NO_ACCESS_CHECK = _BIT (13), /* helper flag for error check */ + PC_SYM_NOFOLLOW_DIR = _BIT (14), /* don't follow a trailing slash */ PC_DONT_USE = _BIT (31) /* conversion to signed happens. */ };
reply other threads:[~2020-01-28 17:02 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200128170222.56830.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /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: linkBe 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).