[RFC PATCH 18/21] entry: use is_dir_sep() when checking leading dirs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The test 'prevent git~1 squatting on Windows' in t7415, adds the file
'd./a/x' and the submodule 'd\a' to the index, with `git -c
core.protectNTFS=false update-index --add --cacheinfo`. Then it performs
a clone with `--recurse-submodules`. Since "d./" and "d\" represent the
same entry on NTFS, the operation is expected to fail, because the
submodule directory is not empty by the time "d\a" is cloned. With
parallel checkout, this condition is still valid: although we call
checkout_entry() for gitlinks before we write regular files (which are
delayed for later parallel write), the actual submodule cloning only
happens after unpack_trees() returns, in builtin/clone.c:checkout().

Note, however, that we do create the submodule directory (and leading
directories) in unpack_trees(). But the current code iterates through
path components only considering "/", not "\", which is also valid on
Windows. The reason we don't fail to create the leading dir "d" for the
gitlink "d\a" is because, by the time we call mkdir("d\a"), "d" was
already created for the regular file 'd./a/x'. Again, this is still true
for parallel checkout, since we create leading dirs sequentially, even
for entries that are delayed for later writing. But in a following patch,
we will allow checkout workers to create the leading directories in
parallel, for better performance. Therefore, when checkout_entry() is
called for the gitlink "d\a", "d" won't be present yet, and mkdir("d\a")
will fail with ENOENT. To solve this, in preparation for the said patch,
let's use is_dir_sep() when checking path components, so that
checkout_entry() can correctly create "d" for the gitlink "d\a".

Signed-off-by: Matheus Tavares <matheus.bernardino@xxxxxx>
---

I'm not sure if this is the right way to make t7415 work with
parallel-checkout; or if we should, perhaps, change the test to add the
submodule at 'a/d'. I'd love if someone more familiar with Windows could
review this one.


 entry.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/entry.c b/entry.c
index 6208df23df..19f2c1d132 100644
--- a/entry.c
+++ b/entry.c
@@ -19,7 +19,7 @@ static void create_directories(const char *path, int path_len,
 		do {
 			buf[len] = path[len];
 			len++;
-		} while (len < path_len && path[len] != '/');
+		} while (len < path_len && !is_dir_sep(path[len]));
 		if (len >= path_len)
 			break;
 		buf[len] = 0;
@@ -404,7 +404,7 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
 {
 	const char *slash = path + len;
 
-	while (path < slash && *slash != '/')
+	while (path < slash && !is_dir_sep(*slash))
 		slash--;
 	if (!has_dirs_only_path(path, slash - path, skiplen)) {
 		errno = ENOENT;
-- 
2.27.0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux