Truncate the feed file before writing
continuous-integration/drone/push Build is passing Details

Otherwise, the feed may be overwritten, but if it is shorter, it may
contain some leftover data from a previous run. In that case, the file
will be invalid XML, thereby failing to be parsed.

Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
This commit is contained in:
Jacob Kiers 2022-12-14 15:54:42 +01:00
parent dae8c50564
commit 86f3430993
2 changed files with 2 additions and 0 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
* Truncate feed file before writing, to prevent corruption from leftover data.
* Ensure the feed file name is part of the self URL. This was still hardcoded to `feed.atom`.
## [0.2.2] - 2022-12-16

View File

@ -203,6 +203,7 @@ fn write_file<P: Into<PathBuf>, D: AsRef<[u8]>>(html_path: P, data: D) -> Result
let path : PathBuf = html_path.into();
OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(&path)
.unwrap_or_else(|_| panic!("Could not open file '{}' for writing", &path.display()))