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 <matheus.bernardino@usp.br> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

Johannes Schindelin committed Feb 2, 2021 at 22:09 UTC 0d58fef58a6f382ba1d35f47a01cb55d8976335f
2 files changed +44 -1
run-command.c
+8 -1
@@ -953,6 +953,7 @@ int finish_command(struct child_process *cmd)
953 {
954 int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
955 child_process_clear(cmd);
956 + invalidate_lstat_cache();
957 return ret;
958 }
959
@@ -1239,13 +1240,19 @@ error:
1240 int finish_async(struct async *async)
1241 {
1242 #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;
1248 #else
1249 void *ret = (void *)(intptr_t)(-1);
1250
1251 if (pthread_join(async->tid, &ret))
1252 error("pthread_join failed");
1253 + invalidate_lstat_cache();
1254 return (int)(intptr_t)ret;
1255 +
1256 #endif
1257 }
1258
t/t0021-conversion.sh
+36
@@ -862,4 +862,40 @@ do
862 '
863 done
864
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 +
901 test_done