Skip to content

Commit 7b3dc92

Browse files
committed
fix: use tempfile permissions support to set the correct mode on unix.
Previousoly it would make an additional syscall to change permissions, which is slower than necessary.
1 parent 3448fd9 commit 7b3dc92

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

gix-odb/Cargo.toml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,25 @@ doctest = false
1515

1616
[features]
1717
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
18-
serde= ["dep:serde", "gix-hash/serde", "gix-object/serde", "gix-pack/serde"]
18+
serde = ["dep:serde", "gix-hash/serde", "gix-object/serde", "gix-pack/serde"]
1919

2020
[dependencies]
21-
gix-features = { version = "^0.38.1", path = "../gix-features", features = ["rustsha1", "walkdir", "zlib", "crc32" ] }
21+
gix-features = { version = "^0.38.1", path = "../gix-features", features = ["rustsha1", "walkdir", "zlib", "crc32"] }
2222
gix-hash = { version = "^0.14.2", path = "../gix-hash" }
2323
gix-date = { version = "^0.8.5", path = "../gix-date" }
2424
gix-path = { version = "^0.10.7", path = "../gix-path" }
2525
gix-quote = { version = "^0.4.12", path = "../gix-quote" }
2626
gix-object = { version = "^0.42.0", path = "../gix-object" }
2727
gix-pack = { version = "^0.50.0", path = "../gix-pack", default-features = false }
2828
gix-fs = { version = "^0.10.2", path = "../gix-fs" }
29-
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
29+
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
3030

31-
tempfile = "3.1.0"
31+
tempfile = "3.10.0"
3232
thiserror = "1.0.26"
3333
parking_lot = { version = "0.12.0" }
3434
arc-swap = "1.5.0"
3535

3636
document-features = { version = "0.2.0", optional = true }
3737

38-
#[dev-dependencies]
39-
#gix-testtools = { path = "../tests/tools"}
40-
#gix-actor = { path = "../gix-actor" }
41-
#pretty_assertions = "1.0.0"
42-
#filetime = "0.2.15"
43-
#maplit = "1.0.2"
44-
#crossbeam-channel = "0.5.6"
45-
4638
[package.metadata.docs.rs]
4739
features = ["document-features", "serde"]

gix-odb/src/store_impls/loose/write.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,16 @@ impl Store {
107107

108108
impl Store {
109109
fn dest(&self) -> Result<hash::Write<CompressedTempfile>, Error> {
110+
#[cfg_attr(not(unix), allow(unused_mut))]
111+
let mut builder = tempfile::Builder::new();
112+
#[cfg(unix)]
113+
{
114+
use std::os::unix::fs::PermissionsExt;
115+
let perms = std::fs::Permissions::from_mode(0o444);
116+
builder.permissions(perms);
117+
}
110118
Ok(hash::Write::new(
111-
deflate::Write::new(NamedTempFile::new_in(&self.path).map_err(|err| Error::Io {
119+
deflate::Write::new(builder.tempfile_in(&self.path).map_err(|err| Error::Io {
112120
source: err,
113121
message: "create named temp file in",
114122
path: self.path.to_owned(),
@@ -144,24 +152,6 @@ impl Store {
144152
return Ok(id);
145153
}
146154
}
147-
#[cfg(unix)]
148-
if let Ok(mut perm) = object_path.metadata().map(|m| m.permissions()) {
149-
use std::os::unix::fs::PermissionsExt;
150-
/// For now we assume the default with standard umask. This can be more sophisticated,
151-
/// but we have the bare minimum.
152-
fn comp_mode(_mode: u32) -> u32 {
153-
0o444
154-
}
155-
let new_mode = comp_mode(perm.mode());
156-
if (perm.mode() ^ new_mode) & !0o170000 != 0 {
157-
perm.set_mode(new_mode);
158-
std::fs::set_permissions(&object_path, perm).map_err(|err| Error::Io {
159-
source: err,
160-
message: "Failed to set permission bits",
161-
path: object_path.clone(),
162-
})?;
163-
}
164-
}
165155
res.map_err(|err| Error::Persist {
166156
source: err,
167157
target: object_path,

0 commit comments

Comments
 (0)