From c4d371d16393aad9a28b420bdeb844544ee4ea13 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Wed, 30 Aug 2023 23:39:24 +0900 Subject: [PATCH] hlssink3: Use Path API for getting file name Current implementation does not support Windows path separator. Use Path API instead. Part-of: --- net/hlssink3/src/imp.rs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/net/hlssink3/src/imp.rs b/net/hlssink3/src/imp.rs index 9061dd96..6aba3a97 100644 --- a/net/hlssink3/src/imp.rs +++ b/net/hlssink3/src/imp.rs @@ -374,13 +374,18 @@ impl HlsSink3 { fn segment_filename(&self, state: &mut StartedState) -> String { assert!(state.current_segment_location.is_some()); - let segment_filename = path_basename(state.current_segment_location.take().unwrap()); + let name = state.current_segment_location.take().unwrap(); + let segment_filename = path::Path::new(&name) + .file_name() + .unwrap() + .to_str() + .unwrap(); let settings = self.settings.lock().unwrap(); if let Some(playlist_root) = &settings.playlist_root { format!("{playlist_root}/{segment_filename}") } else { - segment_filename + segment_filename.to_string() } } @@ -1006,26 +1011,3 @@ impl ElementImpl for HlsSink3 { } } } - -/// The content of the last item of a path separated by `/` character. -fn path_basename(name: impl AsRef) -> String { - name.as_ref().split('/').last().unwrap().to_string() -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn can_extract_basenames() { - for (input, output) in [ - ("", ""), - ("value", "value"), - ("/my/nice/path.ts", "path.ts"), - ("file.ts", "file.ts"), - ("https://localhost/output/file.vtt", "file.vtt"), - ] { - assert_eq!(path_basename(input), output); - } - } -}