diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-08 10:13:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 15:13:13 +0000 |
commit | 88b5fd90880b78498d0bbbdec6342b3db5887ef1 (patch) | |
tree | f3c0e4b99d3253c30c9a6f9625c7ac926d0b83c9 /cli/util/progress_bar/mod.rs | |
parent | 72fe9bb47005e720444e65a66e91559287137780 (diff) |
fix: attempt to only allow one deno process to update the node_modules folder at a time (#18058)
This is implemented in such a way that it should still allow processes
to go through when a file lock wasn't properly cleaned up and the OS
hasn't released it yet (but with a 200ms-ish delay).
Closes #18039
Diffstat (limited to 'cli/util/progress_bar/mod.rs')
-rw-r--r-- | cli/util/progress_bar/mod.rs | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/cli/util/progress_bar/mod.rs b/cli/util/progress_bar/mod.rs index 004b48b2f..256871079 100644 --- a/cli/util/progress_bar/mod.rs +++ b/cli/util/progress_bar/mod.rs @@ -23,6 +23,21 @@ mod renderer; // Inspired by Indicatif, but this custom implementation allows // for more control over what's going on under the hood. +#[derive(Debug, Clone, Copy)] +pub enum ProgressMessagePrompt { + Download, + Blocking, +} + +impl ProgressMessagePrompt { + pub fn as_text(&self) -> String { + match self { + ProgressMessagePrompt::Download => colors::green("Download").to_string(), + ProgressMessagePrompt::Blocking => colors::cyan("Blocking").to_string(), + } + } +} + #[derive(Debug)] pub struct UpdateGuard { maybe_entry: Option<ProgressBarEntry>, @@ -59,6 +74,7 @@ pub enum ProgressBarStyle { #[derive(Clone, Debug)] struct ProgressBarEntry { id: usize, + prompt: ProgressMessagePrompt, pub message: String, pos: Arc<AtomicU64>, total_size: Arc<AtomicU64>, @@ -128,11 +144,16 @@ impl ProgressBarInner { } } - pub fn add_entry(&self, message: String) -> ProgressBarEntry { + pub fn add_entry( + &self, + kind: ProgressMessagePrompt, + message: String, + ) -> ProgressBarEntry { let mut internal_state = self.state.lock(); let id = internal_state.total_entries; let entry = ProgressBarEntry { id, + prompt: kind, message, pos: Default::default(), total_size: Default::default(), @@ -208,6 +229,7 @@ impl DrawThreadRenderer for ProgressBarInner { pending_entries: state.entries.len(), total_entries: state.total_entries, display_entry: ProgressDataDisplayEntry { + prompt: preferred_entry.prompt, message: preferred_entry.message.clone(), position: preferred_entry.position(), total_size: preferred_entry.total_size(), @@ -255,9 +277,17 @@ impl ProgressBar { } pub fn update(&self, msg: &str) -> UpdateGuard { + self.update_with_prompt(ProgressMessagePrompt::Download, msg) + } + + pub fn update_with_prompt( + &self, + kind: ProgressMessagePrompt, + msg: &str, + ) -> UpdateGuard { match &self.inner { Some(inner) => { - let entry = inner.add_entry(msg.to_string()); + let entry = inner.add_entry(kind, msg.to_string()); UpdateGuard { maybe_entry: Some(entry), } @@ -265,7 +295,7 @@ impl ProgressBar { None => { // if we're not running in TTY, fallback to using logger crate if !msg.is_empty() { - log::log!(log::Level::Info, "{} {}", colors::green("Download"), msg); + log::log!(log::Level::Info, "{} {}", kind.as_text(), msg); } UpdateGuard { maybe_entry: None } } |