git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH] mingw: align symlinks-related rmdir() behavior with Linux
Date: Mon, 2 Aug 2021 22:28:26 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2108022218120.55@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <CAPig+cR9rb+ydc5age+2FzLtTtXhg1t77p5NrA7bqN0iyU6Kyg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4048 bytes --]

Hi Eric,

On Thu, 29 Jul 2021, Eric Sunshine wrote:

> On Thu, Jul 29, 2021 at 3:21 PM Johannes Schindelin via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > When performing a rebase, rmdir() is called on the folder .git/logs. On
> > Unix rmdir() exits without deleting anything in case .git/logs is a
> > symbolic link but the equivalent functions on Windows (_rmdir, _wrmdir
> > and RemoveDirectoryW) do not behave the same and remove the folder if it
> > is symlinked even if it is not empty.
> >
> > This creates issues when folders in .git/ are symlinks which is
> > especially the case when git-repo[1] is used.
>
> "issues" is a rather nebulous word. It doesn't help the reader
> understand what actually goes wrong. Presumably some step later in the
> rebase fails? Or is the problem that subsequent interaction with
> git-repo fails because the link which git-repo (presumably) created
> disappears out from underneath it?

I added a few lines describing the problem that was observed, what the
code specifically does to cause the problem, and then documented also that
the regression test specifically verifies that the observed problem won't
reoccur.

> > This commit updates mingw_rmdir() so that its behavior is the same as
> > Linux rmdir() in case of symbolic links.
>
> Okay, makes sense so far as the above explanation goes. But it also
> feels like a band-aid fix to support a use-case which only works by
> accident on Unix, if I'm reading between the lines correctly. That is,
> presumably rmdir(".git/logs") is an intended cleanup action but the
> fact that the cleanup doesn't happen as intended when it is a symlink
> is not intentional behavior, thus git-repo's reliance upon that
> behavior is questionable.

It is the `remove_path()` function that tries to delete parent directories
recursively until things fail.

Whether git-repo's reliance upon that behavior questionable is outside the
purview of this patch. At this point in time, with so many Git versions
accommodating that behavior, I would not want to spend much time pondering
that question, though: we de facto supported that expectation for too long
to change the behavior on Git's side, and therefore adjusting the Windows
side to that expectation feels like the most pragmatic way forward.

> I guess this would also help tools which replace .git/worktrees with a
> symlink since git-worktree -- as a cleanup -- removes its
> .git/worktrees directory when the last worktree is removed...

Yes, indeed.

> > Signed-off-by: Thomas Bétous <tomspycell@gmail.com>
> > ---
> >  compat/mingw.c    | 15 +++++++++++++++
> > diff --git a/compat/mingw.c b/compat/mingw.c
> > @@ -341,6 +341,21 @@ int mingw_rmdir(const char *pathname)
> > +       /*
> > +       * Contrary to Linux rmdir(), Windows' _wrmdir() and _rmdir()
> > +       * will remove the directory at the path if it is a symbolic link
> > +       * which leads to issues when symlinks are used in the .git folder
> > +       * (in the context of git-repo for instance). So before calling _wrmdir()
> > +       * we first check if the path is a symbolic link. If it is, we exit
> > +       * and return the same error as Linux rmdir() in this case (ENOTDIR).
> > +       */
> > +       if (!mingw_lstat(pathname, &st) && S_ISLNK(st.st_mode)) {
> > +               errno = ENOTDIR;
> > +               return -1;
> > +       }
>
> Unfortunately, this code comment doesn't help future readers
> understand when/how this case can be triggered, which means that
> anyone working on this code in the future will have to consult the
> commit message anyhow in order to obtain the necessary understanding.
> This suggests that either the comment should be dropped altogether,
> thus forcing the person to consult the commit message (probably
> undesirable), or improved to give enough information to understand
> when/how it can be triggered.

Okay. I reworded the comment extensively, to address your concern.

Ciao,
Dscho

  reply	other threads:[~2021-08-02 20:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 19:21 [PATCH] mingw: align symlinks-related rmdir() behavior with Linux Johannes Schindelin via GitGitGadget
2021-07-29 19:23 ` Johannes Schindelin
2021-07-29 20:03 ` Junio C Hamano
2021-08-02 20:17   ` Johannes Schindelin
2021-07-29 20:12 ` Eric Sunshine
2021-08-02 20:28   ` Johannes Schindelin [this message]
2021-08-02 21:07 ` [PATCH v2] " Johannes Schindelin via GitGitGadget

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.2108022218120.55@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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