Skip to content

Commit

Permalink
[format version bump v2] Add mode field
Browse files Browse the repository at this point in the history
Include a mode field in the ObjectMetadata and bump the version.

Compatibility notes:

* This elfshaker commit will still be able to read old elfshaker pack
  index files, because the default of an optional is None, which gives
  us exactly the old behaviour of elfshaker prior to this commit.

* elfshaker after this commit will produce packfiles that cannot be read
  by older commits of elfshaker. However, those old versions will report
  to the user that the version they have is too old and point them to
  where they can obtain a newer version.

The biggest risk here is that someone using the main branch makes
packfiles, and distributes those packfiles to a user who is not able to
build elfshaker, and we have not yet gotten around to releasing a new
version of elfshaker. So we should aim for a release of a new version
reasonably soon so that users don't find themselves in this situation
where they can't get an elfshaker which can read the packfiles they have
been provided.

Using an old elfshaker to produce packfiles and ship them to users of
any version of elfshaker is intended to be supported in principle.
  • Loading branch information
peterwaller-arm committed Jan 28, 2023
1 parent 175b003 commit 8d45da3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/packidx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ impl<'a> From<FileEntryRef<'a>> for FileEntry {
pub struct ObjectMetadata {
pub offset: u64,
pub size: u64,
#[serde(default)] // New in Version::V2, None if missing.
pub mode: Option<u32>,
}

/// Contains the metadata needed to extract files from a pack file.
Expand Down Expand Up @@ -580,15 +582,15 @@ impl PackIndex {
}
let mut version = [0; 4];
rd.read_exact(&mut version)?;
if version.gt(&[0, 0, 0, 1]) {
if version.gt(&[0, 0, 0, 2]) {
return Err(PackError::BadPackVersion(version));
}
Ok(())
}

fn write_magic(wr: &mut impl Write) -> std::io::Result<()> {
wr.write_all(b"ELFS")?;
wr.write_all(&[0, 0, 0, 1])?;
wr.write_all(&[0, 0, 0, 2])?;
Ok(())
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/repo/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ fn assign_to_frames(
ObjectMetadata {
offset: local_offset, // Replace global offset -> local offset
size: entry.metadata.size,
mode: None,
},
);
frames[frame_index].push(local_entry);
Expand Down Expand Up @@ -679,7 +680,11 @@ mod tests {
use super::*;

fn make_md(offset: u64, size: u64) -> ObjectMetadata {
ObjectMetadata { offset, size }
ObjectMetadata {
offset,
size,
mode: None,
}
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/repo/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ impl Repository {
ObjectMetadata {
offset: LOOSE_OBJECT_OFFSET,
size: buf.len() as u64,
mode: None,
},
))
})
Expand Down Expand Up @@ -1311,6 +1312,7 @@ mod tests {
static EXAMPLE_MD: ObjectMetadata = ObjectMetadata {
size: 1,
offset: LOOSE_OBJECT_OFFSET,
mode: None,
};

#[test]
Expand Down

0 comments on commit 8d45da3

Please sign in to comment.