Skip to content

Commit

Permalink
Make SourceBundle writer deterministic (#778)
Browse files Browse the repository at this point in the history
The default ZipWriter/FileOptions is using the current timestamp depending on feature flags. Now we explicitly default to a deterministic timestamp for files.
  • Loading branch information
Swatinem authored Mar 28, 2023
1 parent 428f05f commit 657800f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Fixes**:

- PPDB files report `has_sources() = true` even when they only contain source links ([#774](https://github.com/getsentry/symbolic/pull/774))
- Make SourceBundle writer deterministic ([#778](https://github.com/getsentry/symbolic/pull/778))

## 12.1.1

Expand Down
14 changes: 12 additions & 2 deletions symbolic-debuginfo/src/sourcebundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,16 @@ where
collect_il2cpp: bool,
}

fn default_file_options() -> FileOptions {
// TODO: should we maybe acknowledge that its the year 2023 and switch to zstd eventually?
// Though it obviously needs to be supported across the whole platform,
// which does not seem to be the case for Python?

// Depending on `zip` crate feature flags, it might default to the current time.
// Using an explicit `DateTime::default` gives us a deterministic `1980-01-01T00:00:00`.
FileOptions::default().last_modified_time(zip::DateTime::default())
}

impl<W> SourceBundleWriter<W>
where
W: Seek + Write,
Expand Down Expand Up @@ -1125,7 +1135,7 @@ where
let unique_path = self.unique_path(full_path);

self.writer
.start_file(unique_path.clone(), FileOptions::default())
.start_file(unique_path.clone(), default_file_options())
.map_err(|e| SourceBundleError::new(SourceBundleErrorKind::WriteFailed, e))?;
std::io::copy(&mut file, &mut self.writer)
.map_err(|e| SourceBundleError::new(SourceBundleErrorKind::WriteFailed, e))?;
Expand Down Expand Up @@ -1285,7 +1295,7 @@ where
/// Flushes the manifest file to the bundle.
fn write_manifest(&mut self) -> Result<(), SourceBundleError> {
self.writer
.start_file(MANIFEST_PATH, FileOptions::default())
.start_file(MANIFEST_PATH, default_file_options())
.map_err(|e| SourceBundleError::new(SourceBundleErrorKind::WriteFailed, e))?;

serde_json::to_writer(&mut self.writer, &self.manifest)
Expand Down

0 comments on commit 657800f

Please sign in to comment.