Skip to content

Commit 2851e36

Browse files
Check whether TmpGitNamespace request path exists before removing (#1316)
When TmpGitNamespace is dropped before any filtering / git work is done, for example due to an unrelated error, it will attempt to remove directory that doesn't exist because no code that actually uses the namespace path has run. This adds a check before remove_dir_all call to prevent tracing spam. commit-id:9feb11b7
1 parent dd07045 commit 2851e36

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

josh-proxy/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -799,14 +799,18 @@ impl Drop for TmpGitNamespace {
799799
if std::env::var_os("JOSH_KEEP_NS").is_some() {
800800
return;
801801
}
802+
802803
let request_tmp_namespace = self.repo_path.join("refs/namespaces").join(&self.name);
803-
std::fs::remove_dir_all(&request_tmp_namespace).unwrap_or_else(|e| {
804-
tracing::error!(
805-
"remove_dir_all {:?} failed, error:{:?}",
806-
request_tmp_namespace,
807-
e
808-
)
809-
});
804+
805+
if std::path::Path::new(&request_tmp_namespace).exists() {
806+
fs::remove_dir_all(&request_tmp_namespace).unwrap_or_else(|err| {
807+
tracing::error!(
808+
"remove_dir_all {} failed, error: {}",
809+
request_tmp_namespace.display(),
810+
err
811+
)
812+
});
813+
}
810814
}
811815
}
812816

0 commit comments

Comments
 (0)