713131367f
Two related races on recipes/<r>/target/<target>/sysroot, hit by llvm-native during a -j 20 redbear-full build: repo: failed to build: Renaming failed from '.../sysroot.tmp' to '.../sysroot': File exists (os error 17) llvm-native, llvm-native.dev and llvm-native.runtime are package variants of one recipe and share that target directory. The cook_jobs pool runs them as concurrent threads in a single process, so: 1. Shared staging path. Every variant used the same '<sysroot>.tmp', and create_dir_clean() at the start of the staging block would wipe a sibling's half-populated tree while it was still extracting pkgars into it. Staging is now per-call, named from an atomic counter (a pid would not disambiguate -- the pool is threads, not processes). 2. TOCTOU on the publish. The '!deps_dir.is_dir()' guard is checked long before the rename, so all variants can pass it and then race; rename(2) returns EEXIST/ENOTEMPTY once a winner has published a non-empty directory, and the losers failed the whole recipe. Losing is harmless -- every variant populates from the same recipe's dep set, so the winner's tree is equivalent -- so the losers now discard their staging and use it. The destination is deliberately not removed first, since a concurrent cook may already be reading it.