mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-24 16:46:25 +00:00
hlssink3: Write playlists atomically
We want to try to ensure that playlist files are written completely in a single shot, to avoid the possibility of serving up a patially written playlist. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2098>
This commit is contained in:
parent
9453e021dc
commit
1b866222eb
1 changed files with 24 additions and 13 deletions
|
@ -510,19 +510,30 @@ impl HlsBaseSink {
|
||||||
where
|
where
|
||||||
P: AsRef<path::Path>,
|
P: AsRef<path::Path>,
|
||||||
{
|
{
|
||||||
let file = fs::File::create(location).map_err(move |err| {
|
let file = gio::File::for_path(location);
|
||||||
let error_msg = gst::error_msg!(
|
// Open the file for writing, creating it if it doesn't exist
|
||||||
gst::ResourceError::OpenWrite,
|
// Use replace() to write the content in atomic mode
|
||||||
[
|
// (writes to a temporary file and then atomically rename over the destination when the stream is closed)
|
||||||
"Could not open file {} for writing: {}",
|
let output_stream = file
|
||||||
location.as_ref().to_str().unwrap(),
|
.replace(
|
||||||
err.to_string(),
|
None,
|
||||||
]
|
false,
|
||||||
);
|
gio::FileCreateFlags::empty(),
|
||||||
self.post_error_message(error_msg);
|
None::<&gio::Cancellable>,
|
||||||
err.to_string()
|
)
|
||||||
})?;
|
.map_err(move |err| {
|
||||||
Ok(gio::WriteOutputStream::new(file).upcast())
|
let error_msg = gst::error_msg!(
|
||||||
|
gst::ResourceError::OpenWrite,
|
||||||
|
[
|
||||||
|
"Could not open file {} for writing: {}",
|
||||||
|
location.as_ref().to_str().unwrap(),
|
||||||
|
err.to_string(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
self.post_error_message(error_msg);
|
||||||
|
err.to_string()
|
||||||
|
})?;
|
||||||
|
Ok(output_stream.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_fragment<P>(&self, location: &P)
|
fn delete_fragment<P>(&self, location: &P)
|
||||||
|
|
Loading…
Reference in a new issue