Skip to content

Commit

Permalink
Wire up modes
Browse files Browse the repository at this point in the history
Prior to this commit, modes did nothing since they were not populated.
After this commit, they are populated in the index, and that information
is used to specify modes on the created files.

Closes #13.
  • Loading branch information
peterwaller-arm committed Jan 28, 2023
1 parent 8d45da3 commit 57aee2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/repo/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
fs::{self, Permissions},
io,
io::{BufReader, Read, Write},
os::unix::prelude::PermissionsExt,
path::{Path, PathBuf},
};
use std::{fmt::Display, str::FromStr};
Expand Down Expand Up @@ -548,7 +549,7 @@ fn assign_to_frames(
ObjectMetadata {
offset: local_offset, // Replace global offset -> local offset
size: entry.metadata.size,
mode: None,
mode: entry.metadata.mode,
},
);
frames[frame_index].push(local_entry);
Expand Down Expand Up @@ -662,9 +663,15 @@ fn extract_files(
path_buf.clear();
path_buf.push(&output_dir);
path_buf.push(&entry.path);
stats.write_time += measure_ok(|| write_object(&buf[..], &path_buf, None))?
.0
.as_secs_f64();
stats.write_time += measure_ok(|| {
write_object(
&buf[..],
&path_buf,
entry.metadata.mode.map(Permissions::from_mode),
)
})?
.0
.as_secs_f64();
}

Ok(())
Expand Down
18 changes: 15 additions & 3 deletions src/repo/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use super::{constants::*, pack::IdError};

use std::{
collections::{HashMap, HashSet},
fs, io,
fs::{self, File, Permissions},
io,
io::{Read, Write},
os::unix::prelude::PermissionsExt,
path::{Path, PathBuf},
str::FromStr,
sync::atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -581,7 +583,11 @@ impl Repository {
let threads = num_cpus::get();

let pack_entries = run_in_parallel(threads, files.into_iter(), |file_path| {
let buf = fs::read(&file_path)?;
let mut fd = File::open(&file_path)?;
let mut buf = vec![];
fd.read_to_end(&mut buf)?;
let mode = fd.metadata()?.permissions().mode();
drop(fd);
let mut checksum = [0u8; 20];
let mut hasher = Sha1::new();
hasher.input(&buf);
Expand All @@ -594,7 +600,7 @@ impl Repository {
ObjectMetadata {
offset: LOOSE_OBJECT_OFFSET,
size: buf.len() as u64,
mode: None,
mode: Some(mode),
},
))
})
Expand Down Expand Up @@ -1020,6 +1026,12 @@ impl Repository {
),
)
})?;

entry
.metadata
.mode
.map(Permissions::from_mode)
.map_or(Ok(()), |p| fs::set_permissions(&dest_path, p))?;
}

if verify {
Expand Down

0 comments on commit 57aee2f

Please sign in to comment.