Skip to content

Only remove the venv_root directory if it has contents #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions py/tools/py/src/venv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
fs::{self},
path::Path,
path::{Path, PathBuf},
};

use miette::{Context, IntoDiagnostic};
Expand All @@ -18,10 +18,19 @@ pub fn create_venv(
venv_name: &str,
) -> miette::Result<()> {
if location.exists() {
// Clear down the an old venv if there is one present.
fs::remove_dir_all(location)
// With readOnlyRootFilesystem (k8s), we mount a writable volume here with an empty directory.
// In that case, we cannot delete that directory.
let mut contents = PathBuf::from(location)
.read_dir()
.into_diagnostic()
.wrap_err("Unable to remove venv_root directory")?;
.wrap_err("Unable to read venv_root directory")?;
let is_not_empty = contents.next().is_some();
if is_not_empty {
// Clear down the an old venv if there is one present.
fs::remove_dir_all(location)
.into_diagnostic()
.wrap_err("Unable to remove venv_root directory")?;
}
}

// Create all the dirs down to the venv base
Expand Down