From 2851e36c0dc607d4931c04fb324ae460aade7628 Mon Sep 17 00:00:00 2001 From: Vlad Ivanov Date: Thu, 7 Mar 2024 11:53:39 +0100 Subject: [PATCH] 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 --- josh-proxy/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/josh-proxy/src/lib.rs b/josh-proxy/src/lib.rs index ea3b90a9..d33917a3 100644 --- a/josh-proxy/src/lib.rs +++ b/josh-proxy/src/lib.rs @@ -799,14 +799,18 @@ impl Drop for TmpGitNamespace { if std::env::var_os("JOSH_KEEP_NS").is_some() { return; } + let request_tmp_namespace = self.repo_path.join("refs/namespaces").join(&self.name); - std::fs::remove_dir_all(&request_tmp_namespace).unwrap_or_else(|e| { - tracing::error!( - "remove_dir_all {:?} failed, error:{:?}", - request_tmp_namespace, - e - ) - }); + + if std::path::Path::new(&request_tmp_namespace).exists() { + fs::remove_dir_all(&request_tmp_namespace).unwrap_or_else(|err| { + tracing::error!( + "remove_dir_all {} failed, error: {}", + request_tmp_namespace.display(), + err + ) + }); + } } }