All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] refs: work around network caching on Windows
@ 2022-07-15  8:06 Johannes Schindelin via GitGitGadget
  2022-07-15  8:29 ` Eric Sunshine
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2022-07-15  8:06 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Pierre Garnier

From: Pierre Garnier <pgarnier@mega.com>

Network shares sometimes use aggressive caching, in which case a
just-created directory might not be immediately visible to Git.

One symptom of this scenario is the following error:

	$ git tag -a -m "automatic tag creation"  test_dir/test_tag
	fatal: cannot lock ref 'refs/tags/test_dir/test_tag': unable to resolve reference 'refs/tags/test_dir/test_tag': Not a directory

Note: This does not necessarily happen in all Windows setups. One setup
where it _did_ happen is a Windows Server 2019 VM, and as hinted in

	http://woshub.com/slow-network-shared-folder-refresh-windows-server/

the following commands worked around it:

	Set-SmbClientConfiguration -DirectoryCacheLifetime 0
	Set-SmbClientConfiguration -FileInfoCacheLifetime 0
	Set-SmbClientConfiguration -FileNotFoundCacheLifetime 0

This would impact performance negatively, though, as it essentially
turns off all caching, therefore we do not want to require users to do
that just to be able to use Git on Windows.

The underlying culprit is that `GetFileAttributesExW()` that is called from
`mingw_lstat()` can raise an error `ERROR_PATH_NOT_FOUND`, which is
translated to `ENOTDIR`, as opposed to `ENOENT` as expected on Linux.

Therefore, when trying to read a ref, let's allow `ENOTDIR` in addition
to `ENOENT` to indicate that said ref is missing.

This fixes https://github.com/git-for-windows/git/issues/3727

Signed-off-by: Pierre Garnier <pgarnier@mega.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    refs: work around network caching on Windows
    
    While it is enough on Linux to look at ENOENT when allowing for missing
    refs, on Windows we also need to allow ENOTDIR.
    
    This fixes https://github.com/git-for-windows/git/issues/3727

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1291%2Fdscho%2Fenotdir-and-enoent-can-indicate-missing-refs-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1291/dscho/enotdir-and-enoent-can-indicate-missing-refs-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1291

 refs/files-backend.c  | 2 +-
 refs/packed-backend.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 8db7882aacb..b2a880f62f0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -381,7 +381,7 @@ stat_ref:
 	if (lstat(path, &st) < 0) {
 		int ignore_errno;
 		myerr = errno;
-		if (myerr != ENOENT || skip_packed_refs)
+		if ((myerr != ENOENT && myerr != ENOTDIR) || skip_packed_refs)
 			goto out;
 		if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
 				      referent, type, &ignore_errno)) {
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 97b68377673..23d478627a7 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -480,7 +480,7 @@ static int load_contents(struct snapshot *snapshot)
 
 	fd = open(snapshot->refs->path, O_RDONLY);
 	if (fd < 0) {
-		if (errno == ENOENT) {
+		if (errno == ENOENT || errno == ENOTDIR) {
 			/*
 			 * This is OK; it just means that no
 			 * "packed-refs" file has been written yet,

base-commit: bbea4dcf42b28eb7ce64a6306cdde875ae5d09ca
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-07-29 10:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15  8:06 [PATCH] refs: work around network caching on Windows Johannes Schindelin via GitGitGadget
2022-07-15  8:29 ` Eric Sunshine
2022-07-15 12:11   ` Johannes Schindelin
2022-07-15 17:47   ` Junio C Hamano
2022-07-15  8:30 ` Ævar Arnfjörð Bjarmason
2022-07-28 14:29 ` [PATCH v2] lstat(mingw): correctly detect ENOTDIR scenarios Johannes Schindelin via GitGitGadget
2022-07-28 17:37   ` Junio C Hamano
2022-07-28 23:27   ` Eric Sunshine
2022-07-29 10:05   ` [PATCH v3] " Johannes Schindelin via GitGitGadget

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.