diff --git a/Cargo.lock b/Cargo.lock
index 210223423..81095d706 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4689,6 +4689,7 @@ dependencies = [
"bytes",
"clap",
"env_logger",
+ "fastrand",
"filetime",
"flate2",
"futures",
diff --git a/twoliter/Cargo.toml b/twoliter/Cargo.toml
index 972de88b8..4a2e04534 100644
--- a/twoliter/Cargo.toml
+++ b/twoliter/Cargo.toml
@@ -18,6 +18,7 @@ base64.workspace = true
buildsys-config.workspace = true
clap = { workspace = true, features = ["derive", "env", "std"] }
env_logger.workspace = true
+fastrand.workspace = true
filetime.workspace = true
flate2.workspace = true
futures.workspace = true
diff --git a/twoliter/embedded/Makefile.toml b/twoliter/embedded/Makefile.toml
index 3962a457f..0e91001a4 100644
--- a/twoliter/embedded/Makefile.toml
+++ b/twoliter/embedded/Makefile.toml
@@ -837,13 +837,13 @@ else
exit 1
fi
-rm -f "${BUILDSYS_CARGO_METADATA_PATH}"
+temp_file=$(mktemp -p "$(dirname "${BUILDSYS_CARGO_METADATA_PATH}")" metadata.tmp.XXXXXX)
cargo metadata \
--format-version 1 \
--manifest-path "${PROJECT_MANIFEST}" \
--offline \
--all-features \
- > "${BUILDSYS_CARGO_METADATA_PATH}"
+ > "${temp_file}" && mv -f "${temp_file}" "${BUILDSYS_CARGO_METADATA_PATH}"
'''
]
@@ -998,6 +998,11 @@ run_cargo_deny="
(cd /tmp/sources && cargo deny --all-features check --disable-fetch licenses bans sources)
"
set +e
+exec 9<>.cargo/vendor.lock
+if ! flock -w 90 9; then
+ echo "failed to obtain lock" >&2
+ exit 1
+fi
docker run --rm \
--network=none \
--user "$(id -u):$(id -g)" \
diff --git a/twoliter/src/common.rs b/twoliter/src/common.rs
index 2a1190900..3e0aec8c4 100644
--- a/twoliter/src/common.rs
+++ b/twoliter/src/common.rs
@@ -1,6 +1,12 @@
use anyhow::{ensure, Context, Result};
+use filetime::FileTime;
use log::{self, LevelFilter};
+use std::io::ErrorKind;
+use std::path::{Path, PathBuf};
+use std::time::Duration;
+use tokio::fs::OpenOptions;
use tokio::process::Command;
+use tokio::time::sleep;
use tracing::{debug, instrument};
/// This is passed as an environment variable to Buildsys. Buildsys tells Cargo to watch this
@@ -69,6 +75,7 @@ pub(crate) async fn exec(cmd: &mut Command, quiet: bool) -> Result