Skip to content

Commit 0d58fef

Browse files
dschomatheustavares
andcommitted
run-command: invalidate lstat cache after a command finished
In the previous commit, we intercepted calls to `rmdir()` to invalidate the lstat cache in the successful case, so that the lstat cache could not have the idea that a directory exists where there is none. The same situation can arise, of course, when a separate process is spawned (most notably, this is the case in `submodule_move_head()`). Obviously, we cannot know whether a directory was removed in that process, therefore we must invalidate the lstat cache afterwards. Note: in contrast to `lstat_cache_aware_rmdir()`, we invalidate the lstat cache even in case of an error: the process might have removed a directory and still have failed afterwards. Co-authored-by: Matheus Tavares <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 684dd4c commit 0d58fef

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

run-command.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ int finish_command(struct child_process *cmd)
953953
{
954954
int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
955955
child_process_clear(cmd);
956+
invalidate_lstat_cache();
956957
return ret;
957958
}
958959

@@ -1239,13 +1240,19 @@ int start_async(struct async *async)
12391240
int finish_async(struct async *async)
12401241
{
12411242
#ifdef NO_PTHREADS
1242-
return wait_or_whine(async->pid, "child process", 0);
1243+
int ret = wait_or_whine(async->pid, "child process", 0);
1244+
1245+
invalidate_lstat_cache();
1246+
1247+
return ret;
12431248
#else
12441249
void *ret = (void *)(intptr_t)(-1);
12451250

12461251
if (pthread_join(async->tid, &ret))
12471252
error("pthread_join failed");
1253+
invalidate_lstat_cache();
12481254
return (int)(intptr_t)ret;
1255+
12491256
#endif
12501257
}
12511258

t/t0021-conversion.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,4 +862,40 @@ do
862862
'
863863
done
864864

865+
test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \
866+
"delayed checkout with submodule collision don't write to the wrong place" '
867+
git init collision-with-submodule &&
868+
(
869+
cd collision-with-submodule &&
870+
git config filter.delay.process "\"$TEST_ROOT/rot13-filter.pl\" --always-delay delayed.log clean smudge delay" &&
871+
git config filter.delay.required true &&
872+
873+
# We need Git to treat the submodule "a" and the
874+
# leading dir "A" as different paths in the index.
875+
git config --local core.ignoreCase false &&
876+
877+
empty_oid=$(printf "" | git hash-object -w --stdin) &&
878+
attr_oid=$(echo "A/B/y filter=delay" | git hash-object -w --stdin) &&
879+
cat >objs <<-EOF &&
880+
100644 blob $empty_oid A/B/x
881+
100644 blob $empty_oid A/B/y
882+
100644 blob $attr_oid .gitattributes
883+
EOF
884+
git update-index --index-info <objs &&
885+
886+
git init a &&
887+
mkdir target-dir &&
888+
symlink_oid=$(printf "%s" "$PWD/target-dir" | git -C a hash-object -w --stdin) &&
889+
echo "120000 blob $symlink_oid b" >objs &&
890+
git -C a update-index --index-info <objs &&
891+
git -C a commit -m sub &&
892+
git submodule add ./a &&
893+
git commit -m super &&
894+
895+
git checkout --recurse-submodules . &&
896+
grep "IN: smudge A/B/y .* \\[DELAYED\\]" delayed.log &&
897+
test_path_is_missing target-dir/y
898+
)
899+
'
900+
865901
test_done

0 commit comments

Comments
 (0)