Skip to content

Commit

Permalink
Check whether TmpGitNamespace request path exists before removing (#1316
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
vlad-ivanov-name authored Mar 7, 2024
1 parent dd07045 commit 2851e36
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions josh-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
});
}
}
}

Expand Down

0 comments on commit 2851e36

Please sign in to comment.