From 748cd23f333850a6b751c60911b409f49a97d958 Mon Sep 17 00:00:00 2001 From: Kris Foster Date: Mon, 27 Jan 2025 17:57:00 +0000 Subject: [PATCH 1/4] readOnlyRootFilesystem --- py/tools/py/src/venv.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/py/tools/py/src/venv.rs b/py/tools/py/src/venv.rs index cc55ce24..514860bd 100644 --- a/py/tools/py/src/venv.rs +++ b/py/tools/py/src/venv.rs @@ -18,10 +18,15 @@ 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) - .into_diagnostic() - .wrap_err("Unable to remove venv_root directory")?; + // With readOnlyRootFilesystem (k8s), we mount a writable volume here with an empty directory. + // In that case, we cannot delete that directory. + let is_empty = location.read_dir()?.next().is_none(); + if is_empty.not() { + // 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 From 9fd6ed3963fd113e6ddbf6d8a9320213293c2952 Mon Sep 17 00:00:00 2001 From: Kris Foster Date: Mon, 27 Jan 2025 18:03:46 +0000 Subject: [PATCH 2/4] indentation --- py/tools/py/src/venv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/tools/py/src/venv.rs b/py/tools/py/src/venv.rs index 514860bd..fb4435c0 100644 --- a/py/tools/py/src/venv.rs +++ b/py/tools/py/src/venv.rs @@ -26,7 +26,7 @@ pub fn create_venv( fs::remove_dir_all(location) .into_diagnostic() .wrap_err("Unable to remove venv_root directory")?; - } + } } // Create all the dirs down to the venv base From cc5bb9c1cf951b200b8ee71173f9fa6717fcc9b3 Mon Sep 17 00:00:00 2001 From: Kris Foster Date: Mon, 27 Jan 2025 18:10:13 +0000 Subject: [PATCH 3/4] not --- py/tools/py/src/venv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/tools/py/src/venv.rs b/py/tools/py/src/venv.rs index fb4435c0..e29b24a1 100644 --- a/py/tools/py/src/venv.rs +++ b/py/tools/py/src/venv.rs @@ -21,7 +21,7 @@ pub fn create_venv( // With readOnlyRootFilesystem (k8s), we mount a writable volume here with an empty directory. // In that case, we cannot delete that directory. let is_empty = location.read_dir()?.next().is_none(); - if is_empty.not() { + if !is_empty { // Clear down the an old venv if there is one present. fs::remove_dir_all(location) .into_diagnostic() From 241c6c7aab0f3abde8f6c11efa0df831c99020a0 Mon Sep 17 00:00:00 2001 From: Kris Foster Date: Tue, 28 Jan 2025 08:51:43 +0000 Subject: [PATCH 4/4] builds --- py/tools/py/src/venv.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/py/tools/py/src/venv.rs b/py/tools/py/src/venv.rs index e29b24a1..f2638457 100644 --- a/py/tools/py/src/venv.rs +++ b/py/tools/py/src/venv.rs @@ -1,6 +1,6 @@ use std::{ fs::{self}, - path::Path, + path::{Path, PathBuf}, }; use miette::{Context, IntoDiagnostic}; @@ -20,8 +20,12 @@ pub fn create_venv( if location.exists() { // With readOnlyRootFilesystem (k8s), we mount a writable volume here with an empty directory. // In that case, we cannot delete that directory. - let is_empty = location.read_dir()?.next().is_none(); - if !is_empty { + let mut contents = PathBuf::from(location) + .read_dir() + .into_diagnostic() + .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()