From 93581a67258e6b25dd96a0ef82422cf06c74bbb9 Mon Sep 17 00:00:00 2001 From: ChrisX001001 Date: Thu, 26 Nov 2026 21:44:01 +0100 Subject: [PATCH 1/2] Serialize model cache downloads and removals --- src/model.rs | 123 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 51 deletions(-) diff --git a/src/model.rs b/src/model.rs index e61fa59..b3e909c 100644 --- a/src/model.rs +++ b/src/model.rs @@ -665,24 +665,36 @@ pub fn partial_size(info: &ModelInfo) -> Option { } pub fn remove_partial(info: &ModelInfo) -> Result<(), String> { - let path = cache_dir().join(format!("{}.part", info.file)); - match fs::remove_file(&path) { - Ok(()) => Ok(()), - Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()), - Err(e) => Err(format!( - "cannot remove partial model {}: {e}", - path.display() - )), - } + let dir = cache_dir(); + remove_cached_files(&dir, info.file, [dir.join(format!("{}.part", info.file))]) } pub fn remove_model(info: &ModelInfo) -> Result<(), String> { let dir = cache_dir(); - for path in [ - dir.join(info.file), - dir.join(format!("{}.part", info.file)), - dir.join(format!(".{}.error", info.file)), - ] { + remove_cached_files( + &dir, + info.file, + [ + dir.join(info.file), + dir.join(format!("{}.part", info.file)), + dir.join(format!(".{}.error", info.file)), + ], + ) +} + +fn remove_cached_files( + dir: &Path, + file: &str, + paths: impl IntoIterator, +) -> Result<(), String> { + if !dir + .try_exists() + .map_err(|e| format!("cannot inspect model directory: {e}"))? + { + return Ok(()); + } + let _lock = DownloadLock::acquire(dir, file)?; + for path in paths { match fs::remove_file(&path) { Ok(()) => {} Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} @@ -692,52 +704,31 @@ pub fn remove_model(info: &ModelInfo) -> Result<(), String> { Ok(()) } -/// one process at a time may touch a given partial file. without this, two -/// scribes can append to the same `.part` and each verify the other's debris. +/// downloading and removing a model both take this lock. the lock file stays +/// in place so every process opens the same file. closing it releases the lock. #[derive(Debug)] -struct DownloadLock(PathBuf); +struct DownloadLock { + _file: fs::File, +} impl DownloadLock { fn acquire(dir: &Path, file: &str) -> Result { - let path = dir.join(format!(".{file}.lock")); - match fs::OpenOptions::new() + let lock = fs::OpenOptions::new() .write(true) - .create_new(true) - .open(&path) - { - Ok(_) => Ok(Self(path)), - Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { - let stale = fs::metadata(&path) - .and_then(|m| m.modified()) - .map(|t| t.elapsed().unwrap_or_default() > std::time::Duration::from_secs(600)) - .unwrap_or(true); - if stale { - let _ = fs::remove_file(&path); - if fs::OpenOptions::new() - .write(true) - .create_new(true) - .open(&path) - .is_ok() - { - return Ok(Self(path)); - } - } - Err(format!( - "another scribe is downloading {file}. wait for it to finish (or remove the stale lock at {})", - path.display() - )) - } - Err(e) => Err(format!("cannot create download lock: {e}")), + .create(true) + .truncate(false) + .open(dir.join(format!(".{file}.cache.lock"))) + .map_err(|e| format!("cannot open model cache lock: {e}"))?; + match lock.try_lock() { + Ok(()) => Ok(Self { _file: lock }), + Err(fs::TryLockError::WouldBlock) => Err(format!( + "another scribe is using the model cache for {file}" + )), + Err(fs::TryLockError::Error(e)) => Err(format!("cannot lock model cache: {e}")), } } } -impl Drop for DownloadLock { - fn drop(&mut self) { - let _ = fs::remove_file(&self.0); - } -} - /// download to a .part file, verify size and sha256, then rename. the rename is /// the commit point: until then, nothing in the cache claims to be a model. pub fn download( @@ -1249,6 +1240,36 @@ mod tests { fs::remove_dir_all(&dir).unwrap(); } + #[test] + fn cache_removal_respects_the_download_lock() { + let dir = std::env::temp_dir().join(format!("scribe-lock-removal-{}", std::process::id())); + let file = "ggml-test.bin"; + let model = dir.join(file); + let partial = dir.join(format!("{file}.part")); + assert!(remove_cached_files(&dir, file, [partial.clone()]).is_ok()); + assert!(!dir.exists()); + + fs::create_dir(&dir).unwrap(); + fs::write(&model, b"model").unwrap(); + fs::write(&partial, b"partial").unwrap(); + let lock = DownloadLock::acquire(&dir, file).unwrap(); + + for paths in [vec![partial.clone()], vec![model.clone(), partial.clone()]] { + let err = remove_cached_files(&dir, file, paths).unwrap_err(); + assert!(err.contains("another scribe")); + } + assert_eq!(fs::read(&model).unwrap(), b"model"); + assert_eq!(fs::read(&partial).unwrap(), b"partial"); + + drop(lock); + remove_cached_files(&dir, file, [partial.clone()]).unwrap(); + assert!(!partial.exists()); + assert!(model.exists()); + remove_cached_files(&dir, file, [model.clone(), partial]).unwrap(); + assert!(!model.exists()); + fs::remove_dir_all(&dir).unwrap(); + } + #[test] fn validate_custom_rejects_stubs_and_wrong_headers() { let dir = std::env::temp_dir().join(format!("scribe-custom-{}", std::process::id())); From c6d2cf02f0c5d63f300c390aa084f9a4c6c67748 Mon Sep 17 00:00:00 2001 From: ChrisX001001 Date: Fri, 27 Nov 2026 11:26:21 +0100 Subject: [PATCH 2/2] Preserve model cache coordination across versions Keep the OS lock for current processes and guard legacy downloaders at the old lock path. Deliver download failures directly to the TUI and exercise both public removal methods. --- Cargo.lock | 1 + Cargo.toml | 3 + src/main.rs | 197 +++++++++++++++++++++++++-------------------------- src/model.rs | 172 +++++++++++++++++++++++++++++++++++--------- src/util.rs | 2 +- 5 files changed, 242 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc8390d..25627a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2577,6 +2577,7 @@ version = "0.3.0" dependencies = [ "crossterm", "ratatui", + "rustix", "sha2 0.11.1", "tokio", "unicode-width", diff --git a/Cargo.toml b/Cargo.toml index 5452c70..075e939 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,9 @@ sha2 = "0.11.1" # locate ffprobe on path; used by the duration detector in worker.rs. which = "8" +[target.'cfg(unix)'.dependencies] +rustix = { version = "1.1", features = ["fs"] } + [profile.release] lto = "fat" codegen-units = 1 diff --git a/src/main.rs b/src/main.rs index 892233b..52eb7ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -249,6 +249,12 @@ fn run_plain(args: &Args) -> Result { } } +enum DownloadOutcome { + Ready, + Paused, + Failed(String), +} + fn run_tui(args: &Args) -> Result<(), String> { let mut guard = TerminalGuard::enter().map_err(|e| format!("could not start the terminal ui: {e}"))?; @@ -280,7 +286,7 @@ fn run_tui(args: &Args) -> Result<(), String> { // cancelled workers keep running until they notice the flag. park their // handles here and reap them in the loop instead of freezing the ui. let mut retiring: Vec = Vec::new(); - let mut downloader: Option> = None; + let mut downloader: Option> = None; let mut download_rx: Option> = None; let mut download_cancel: Option> = None; @@ -295,80 +301,27 @@ fn run_tui(args: &Args) -> Result<(), String> { if let Some(drx) = &download_rx { while let Ok(p) = drx.try_recv() { needs_redraw = true; - if p.bytes_per_sec < 0.0 { - if p.bytes_per_sec == -2.0 { - app.download = app::DownloadState::Idle; - if app.download_discard { - if let Some(info) = app - .download_models - .iter() - .find(|info| info.file == app.download_file) - { - if let Err(e) = model::remove_partial(info) { - app.download_info = e.clone(); - app.set_message(e); - } else { - app.download_info = - "download canceled · partial file removed".into(); - app.toast("download canceled", ToastKind::Warn); - } - } - app.download_discard = false; - app.download_paused = false; - } else { - app.download = app::DownloadState::Idle; - app.download_paused = true; - app.download_info = "paused · enter resumes from saved data".into(); - app.toast("download paused · enter resumes", ToastKind::Info); - } - } else { - let err_path = - model::cache_dir().join(format!(".{}.error", app.download_file)); - let msg = std::fs::read_to_string(&err_path).unwrap_or_else(|_| { - "download failed, and the error note vanished".into() - }); - let _ = std::fs::remove_file(&err_path); - app.download = app::DownloadState::Failed; - app.download_paused = false; - app.download_info = msg.clone(); - app.toast(format!("download failed: {msg}"), ToastKind::Error); - app.set_message(msg); - } - } else { - app.download_frac = p.fraction(); - if p.bytes_per_sec > 0.0 { - app.download_info = format!( - "{}/s eta {}", - human_bytes(p.bytes_per_sec as u64), - p.eta_s() - .map(duration_short) - .unwrap_or_else(|| "--:--".into()) - ); - } + app.download_frac = p.fraction(); + if p.bytes_per_sec > 0.0 { + app.download_info = format!( + "{}/s eta {}", + human_bytes(p.bytes_per_sec as u64), + p.eta_s() + .map(duration_short) + .unwrap_or_else(|| "--:--".into()) + ); } } } if downloader.as_ref().is_some_and(|h| h.is_finished()) { if let Some(h) = downloader.take() { - let _ = h.join(); + let outcome = h.join().unwrap_or_else(|_| { + DownloadOutcome::Failed("download worker stopped unexpectedly".into()) + }); + finish_model_download(&mut app, outcome); } download_rx = None; - if app.download == app::DownloadState::Downloading { - app.download = app::DownloadState::Done; - app.download_paused = false; - app.download_frac = 1.0; - let label = app - .download_models - .iter() - .find(|model| model.file == app.download_file) - .map(|model| model.label) - .unwrap_or("model"); - app.toast( - format!("{label} downloaded and verified"), - ToastKind::Success, - ); - app.set_message(format!("{label} is ready. press enter to select it")); - } + download_cancel = None; needs_redraw = true; } @@ -513,7 +466,7 @@ fn process_key( tx: &mpsc::Sender, handle: &mut Option, retiring: &mut Vec, - downloader: &mut Option>, + downloader: &mut Option>, download_rx: &mut Option>, download_cancel: &mut Option>, picker_rows: usize, @@ -597,10 +550,10 @@ fn process_key( if let Some(c) = download_cancel.take() { c.store(true, std::sync::atomic::Ordering::Relaxed); } - app.download_info = "pausing · saved data will resume on enter".into(); + app.download_info = "pausing · saved data will resume on enter".into(); app.download_paused = true; app.toast( - "download paused · enter resumes from saved data", + "download paused · enter resumes from saved data", ToastKind::Info, ); // Closing the picker should not require waiting for the @@ -616,7 +569,7 @@ fn process_key( if let Some(c) = download_cancel.take() { c.store(true, std::sync::atomic::Ordering::Relaxed); } - app.download_info = "pausing · saved data will resume on enter".into(); + app.download_info = "pausing · saved data will resume on enter".into(); app.download_paused = true; } KeyCode::Char('c') if app.download == app::DownloadState::Downloading => { @@ -625,7 +578,7 @@ fn process_key( if let Some(c) = download_cancel.take() { c.store(true, std::sync::atomic::Ordering::Relaxed); } - app.download_info = "canceling · removing partial download".into(); + app.download_info = "canceling · removing partial download".into(); } KeyCode::Char('x') => { let info = &app.download_models[app.download_index]; @@ -929,9 +882,61 @@ fn change_setting(app: &mut App, forward: bool) { } } +fn finish_model_download(app: &mut App, outcome: DownloadOutcome) { + match outcome { + DownloadOutcome::Ready => { + app.download = app::DownloadState::Done; + app.download_paused = false; + app.download_frac = 1.0; + let label = app + .download_models + .iter() + .find(|model| model.file == app.download_file) + .map(|model| model.label) + .unwrap_or("model"); + app.toast( + format!("{label} downloaded and verified"), + ToastKind::Success, + ); + app.set_message(format!("{label} is ready. press enter to select it")); + } + DownloadOutcome::Paused => { + app.download = app::DownloadState::Idle; + if app.download_discard { + if let Some(info) = app + .download_models + .iter() + .find(|info| info.file == app.download_file) + { + if let Err(err) = model::remove_partial(info) { + app.download_info = err.clone(); + app.set_message(err); + } else { + app.download_info = "download canceled · partial file removed".into(); + app.toast("download canceled", ToastKind::Warn); + } + } + app.download_discard = false; + app.download_paused = false; + } else { + app.download_paused = true; + app.download_info = "paused · enter resumes from saved data".into(); + app.toast("download paused · enter resumes", ToastKind::Info); + } + } + DownloadOutcome::Failed(err) => { + app.download = app::DownloadState::Failed; + app.download_paused = false; + app.download_info = err.clone(); + app.toast(format!("download failed: {err}"), ToastKind::Error); + app.set_message(err); + } + } +} + fn start_download( app: &mut App, - downloader: &mut Option>, + downloader: &mut Option>, download_rx: &mut Option>, download_cancel: &mut Option>, ) { @@ -951,17 +956,6 @@ fn start_download( } return; } - // a finished thread still holding its slot must be reaped before a new - // download starts; otherwise the old join handle can look "live" for a - // frame and enter gets ignored right after a pause. - if let Some(h) = downloader.as_ref() - && h.is_finished() - { - if let Some(h) = downloader.take() { - let _ = h.join(); - } - *download_rx = None; - } if downloader.is_some() { let what = if app.download_paused { "previous download is still stopping; press enter again in a moment" @@ -993,22 +987,12 @@ fn start_download( let result = model::download(&info, &cancel_thread, |p| { let _ = p_tx.send(p); }); - if let Err(e) = result { - if cancel_thread.load(std::sync::atomic::Ordering::Relaxed) { - let _ = p_tx.send(model::DownloadProgress { - downloaded: 0, - total: None, - bytes_per_sec: -2.0, - }); - } else { - let _ = - std::fs::write(model::cache_dir().join(format!(".{}.error", info.file)), &e); - let _ = p_tx.send(model::DownloadProgress { - downloaded: 0, - total: None, - bytes_per_sec: -1.0, - }); + match result { + Ok(_) => DownloadOutcome::Ready, + Err(_) if cancel_thread.load(std::sync::atomic::Ordering::Relaxed) => { + DownloadOutcome::Paused } + Err(err) => DownloadOutcome::Failed(err), } }); *download_cancel = Some(cancel); @@ -1066,6 +1050,19 @@ use util::{duration_short, human_bytes, timestamp_short}; mod tests { use super::*; + #[test] + fn download_failure_uses_worker_result_without_a_cache_note() { + let mut app = App::new(&Args::default()); + app.download = app::DownloadState::Downloading; + app.download_file = "unknown-test-model.bin".into(); + + let worker = std::thread::spawn(|| DownloadOutcome::Failed("download timed out".into())); + finish_model_download(&mut app, worker.join().unwrap()); + + assert!(app.download == app::DownloadState::Failed); + assert_eq!(app.download_info, "download timed out"); + } + #[test] fn terminal_cleanup_continues_after_a_failed_step() { use std::cell::RefCell; diff --git a/src/model.rs b/src/model.rs index b3e909c..d58954a 100644 --- a/src/model.rs +++ b/src/model.rs @@ -412,9 +412,18 @@ pub fn find(key: &str) -> Option<&'static ModelInfo> { /// where models live. xdg if you have it, ~/.cache if you do not. i am not /// going to guess three more conventions and make a mess of your home dir. pub fn cache_dir() -> PathBuf { + #[cfg(test)] + if let Some(dir) = TEST_CACHE_DIR.with(|dir| dir.borrow().clone()) { + return dir; + } crate::util::cache_home().join("scribe").join("models") } +#[cfg(test)] +thread_local! { + static TEST_CACHE_DIR: std::cell::RefCell> = const { std::cell::RefCell::new(None) }; +} + /// What a `--model`/saved value can refer to. Keeping the three forms distinct /// is what makes resolution unambiguous: a catalog name is never also treated /// as a path just because a file with that name happens to exist in `$PWD`. @@ -687,12 +696,6 @@ fn remove_cached_files( file: &str, paths: impl IntoIterator, ) -> Result<(), String> { - if !dir - .try_exists() - .map_err(|e| format!("cannot inspect model directory: {e}"))? - { - return Ok(()); - } let _lock = DownloadLock::acquire(dir, file)?; for path in paths { match fs::remove_file(&path) { @@ -704,31 +707,89 @@ fn remove_cached_files( Ok(()) } -/// downloading and removing a model both take this lock. the lock file stays -/// in place so every process opens the same file. closing it releases the lock. +/// The persistent file serializes current processes. The legacy path uses a +/// directory so older downloaders cannot unlink it as a stale lock file. #[derive(Debug)] struct DownloadLock { + legacy_marker: PathBuf, _file: fs::File, } impl DownloadLock { fn acquire(dir: &Path, file: &str) -> Result { - let lock = fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(false) - .open(dir.join(format!(".{file}.cache.lock"))) + fs::create_dir_all(dir).map_err(|e| format!("cannot create model directory: {e}"))?; + let lock = open_cache_lock(&dir.join(format!(".{file}.cache.lock"))) .map_err(|e| format!("cannot open model cache lock: {e}"))?; + if !lock + .metadata() + .map_err(|e| format!("cannot inspect model cache lock: {e}"))? + .is_file() + { + return Err("model cache lock is not a regular file".into()); + } match lock.try_lock() { - Ok(()) => Ok(Self { _file: lock }), - Err(fs::TryLockError::WouldBlock) => Err(format!( - "another scribe is using the model cache for {file}" - )), - Err(fs::TryLockError::Error(e)) => Err(format!("cannot lock model cache: {e}")), + Ok(()) => {} + Err(fs::TryLockError::WouldBlock) => { + return Err(format!( + "another scribe is using the model cache for {file}" + )); + } + Err(fs::TryLockError::Error(e)) => return Err(format!("cannot lock model cache: {e}")), } + + let legacy_marker = dir.join(format!(".{file}.lock")); + match fs::create_dir(&legacy_marker) { + Ok(()) => {} + Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { + // Only versions that take the OS lock create this directory. + // If it survived a crash, the OS lock lets us adopt it safely. + let is_directory = + fs::symlink_metadata(&legacy_marker).is_ok_and(|metadata| metadata.is_dir()); + if !is_directory { + return Err(format!( + "another scribe is using the model cache for {file} (legacy lock at {})", + legacy_marker.display() + )); + } + } + Err(e) => return Err(format!("cannot create legacy model cache marker: {e}")), + } + Ok(Self { + legacy_marker, + _file: lock, + }) } } +impl Drop for DownloadLock { + fn drop(&mut self) { + let _ = fs::remove_dir(&self.legacy_marker); + } +} + +#[cfg(unix)] +fn open_cache_lock(path: &Path) -> std::io::Result { + use rustix::fs::{Mode, OFlags, open}; + + let flags = + OFlags::RDWR | OFlags::CREATE | OFlags::NONBLOCK | OFlags::NOFOLLOW | OFlags::CLOEXEC; + Ok(open(path, flags, Mode::RUSR | Mode::WUSR).map(File::from)?) +} + +#[cfg(windows)] +fn open_cache_lock(path: &Path) -> std::io::Result { + use std::os::windows::fs::OpenOptionsExt; + + const FILE_FLAG_OPEN_REPARSE_POINT: u32 = 0x00200000; + fs::OpenOptions::new() + .read(true) + .write(true) + .create(true) + .truncate(false) + .custom_flags(FILE_FLAG_OPEN_REPARSE_POINT) + .open(path) +} + /// download to a .part file, verify size and sha256, then rename. the rename is /// the commit point: until then, nothing in the cache claims to be a model. pub fn download( @@ -748,7 +809,6 @@ fn download_from( cancel: &std::sync::Arc, on_progress: impl Fn(DownloadProgress), ) -> Result { - fs::create_dir_all(&dir).map_err(|e| format!("cannot create model directory: {e}"))?; let _lock = DownloadLock::acquire(&dir, info.file)?; let final_path = dir.join(info.file); let part = dir.join(format!("{}.part", info.file)); @@ -1241,32 +1301,80 @@ mod tests { } #[test] - fn cache_removal_respects_the_download_lock() { + fn public_cache_removals_respect_the_download_lock() { let dir = std::env::temp_dir().join(format!("scribe-lock-removal-{}", std::process::id())); - let file = "ggml-test.bin"; - let model = dir.join(file); - let partial = dir.join(format!("{file}.part")); - assert!(remove_cached_files(&dir, file, [partial.clone()]).is_ok()); + let info = tiny_info("unused"); + let model = dir.join(info.file); + let partial = dir.join(format!("{}.part", info.file)); + let error = dir.join(format!(".{}.error", info.file)); + TEST_CACHE_DIR.with(|cache| *cache.borrow_mut() = Some(dir.clone())); + assert!(!dir.exists()); + remove_partial(&info).unwrap(); + assert!(dir.join(format!(".{}.cache.lock", info.file)).is_file()); - fs::create_dir(&dir).unwrap(); fs::write(&model, b"model").unwrap(); fs::write(&partial, b"partial").unwrap(); - let lock = DownloadLock::acquire(&dir, file).unwrap(); + fs::write(&error, b"old note").unwrap(); + let lock = DownloadLock::acquire(&dir, info.file).unwrap(); - for paths in [vec![partial.clone()], vec![model.clone(), partial.clone()]] { - let err = remove_cached_files(&dir, file, paths).unwrap_err(); - assert!(err.contains("another scribe")); - } + assert!( + remove_partial(&info) + .unwrap_err() + .contains("another scribe") + ); + assert!(remove_model(&info).unwrap_err().contains("another scribe")); assert_eq!(fs::read(&model).unwrap(), b"model"); assert_eq!(fs::read(&partial).unwrap(), b"partial"); + assert_eq!(fs::read(&error).unwrap(), b"old note"); drop(lock); - remove_cached_files(&dir, file, [partial.clone()]).unwrap(); + remove_partial(&info).unwrap(); assert!(!partial.exists()); assert!(model.exists()); - remove_cached_files(&dir, file, [model.clone(), partial]).unwrap(); + assert!(error.exists()); + remove_model(&info).unwrap(); assert!(!model.exists()); + assert!(!error.exists()); + TEST_CACHE_DIR.with(|cache| *cache.borrow_mut() = None); + fs::remove_dir_all(&dir).unwrap(); + } + + #[test] + fn legacy_downloads_contend_and_cannot_remove_the_marker() { + let dir = std::env::temp_dir().join(format!("scribe-legacy-lock-{}", std::process::id())); + fs::create_dir(&dir).unwrap(); + let file = "ggml-test.bin"; + let legacy = dir.join(format!(".{file}.lock")); + File::create_new(&legacy).unwrap(); + assert!( + DownloadLock::acquire(&dir, file) + .unwrap_err() + .contains("legacy lock") + ); + fs::remove_file(&legacy).unwrap(); + + // A previous new-version process could have exited before dropping the marker. + fs::create_dir(&legacy).unwrap(); + let lock = DownloadLock::acquire(&dir, file).unwrap(); + assert!(File::create_new(&legacy).is_err()); + assert!(fs::remove_file(&legacy).is_err()); + assert!(legacy.is_dir()); + drop(lock); + + File::create_new(&legacy).unwrap(); + fs::remove_dir_all(&dir).unwrap(); + } + + #[test] + fn cache_lock_rejects_a_directory() { + let dir = std::env::temp_dir().join(format!("scribe-nonfile-lock-{}", std::process::id())); + let file = "ggml-test.bin"; + let lock_path = dir.join(format!(".{file}.cache.lock")); + fs::create_dir_all(&lock_path).unwrap(); + assert!(DownloadLock::acquire(&dir, file).is_err()); + assert!(lock_path.is_dir()); + assert!(!dir.join(format!(".{file}.lock")).exists()); fs::remove_dir_all(&dir).unwrap(); } diff --git a/src/util.rs b/src/util.rs index 67d64cd..4dd1a0a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -691,7 +691,7 @@ mod tests { assert!(!is_youtube_url( "https://notyoutube.com.evil.test/watch?v=x" )); - assert!(!youtube_id("https://notyoutube.com.evil.test/watch?v=x").is_some()); + assert!(youtube_id("https://notyoutube.com.evil.test/watch?v=x").is_none()); assert!(is_youtube_url("https://www.youtube.com/watch?v=abc")); assert_eq!( youtube_id("https://www.youtube.com/watch?v=abc"),