summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLibravatar Jiang Xin <worldhello.net@gmail.com>2021-08-14 07:56:22 +0800
committerLibravatar Jiang Xin <worldhello.net@gmail.com>2021-08-14 07:56:22 +0800
commit117e2caa42210de5c2c1ecfdf5d2bda056cd6f00 (patch)
treec742277e7f21ad2746a807e2c0318a0fae662f5f /compat
parentMerge branch 'master' of github.com:nafmo/git-l10n-sv (diff)
parentGit 2.33-rc2 (diff)
downloadtgif-117e2caa42210de5c2c1ecfdf5d2bda056cd6f00.tar.xz
Merge branch 'master' of github.com:git/git
* 'master' of github.com:git/git: (51 commits) Git 2.33-rc2 object-file: use unsigned arithmetic with bit mask Revert 'diff-merges: let "-m" imply "-p"' object-store: avoid extra ';' from KHASH_INIT oidtree: avoid nested struct oidtree_node Git 2.33-rc1 test: fix for COLUMNS and bash 5 The eighth batch diff: --pickaxe-all typofix mingw: align symlinks-related rmdir() behavior with Linux t7508: avoid non POSIX BRE use fspathhash() everywhere t0001: fix broken not-quite getcwd(3) test in bed67874e2 Documentation: render special characters correctly reset: clear_unpack_trees_porcelain to plug leak builtin/rebase: fix options.strategy memory lifecycle builtin/merge: free found_ref when done builtin/mv: free or UNLEAK multiple pointers at end of cmd_mv convert: release strbuf to avoid leak read-cache: call diff_setup_done to avoid leak ...
Diffstat (limited to 'compat')
-rw-r--r--compat/mingw.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index aa647b367b..9e0cd1e097 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -341,6 +341,27 @@ int mingw_rmdir(const char *pathname)
{
int ret, tries = 0;
wchar_t wpathname[MAX_PATH];
+ struct stat st;
+
+ /*
+ * Contrary to Linux' `rmdir()`, Windows' _wrmdir() and _rmdir()
+ * (and `RemoveDirectoryW()`) will attempt to remove the target of a
+ * symbolic link (if it points to a directory).
+ *
+ * This behavior breaks the assumption of e.g. `remove_path()` which
+ * upon successful deletion of a file will attempt to remove its parent
+ * directories recursively until failure (which usually happens when
+ * the directory is not empty).
+ *
+ * Therefore, 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()` would, i.e. `ENOTDIR`.
+ */
+ if (!mingw_lstat(pathname, &st) && S_ISLNK(st.st_mode)) {
+ errno = ENOTDIR;
+ return -1;
+ }
+
if (xutftowcs_path(wpathname, pathname) < 0)
return -1;