Skip to content

Commit 588e6b0

Browse files
committed
Make set_executable_after_creation everywhere bool
In `finalize_entry` and its callers, `set_executable_after_creation` was previously an `Option<&Path>`, because `chmod` was called (via a higher level abstraction) on the path to make the file executable. From #1764, `lstat` (via a higher level abstraction) was likewise called on the path to find out what its old mode was, to figure out what mode to set to achieve +x. Now that the `lstat` is replaced with `fstat`, and the `chmod` is replaced with `fchmod`, figuring out how to set +x and setting it are done entirely on the file descriptor, with the path unused. It turns out that this was the only use of that path in that context. Accordingly, this makes `set_executable_after_creation` a `bool` in both `finalize_entry` and its callers, and removes code that was only used for handling that path. This includes eliminating the `rela_path_as_path` variable in `checkout::chunk::process_delayed_filter_results`, which was apparently only used for this purpose. (All writes and reads on it were for preparing and passing a path to `finalize_entry`. The `finalize_entry` function had only used it to set the file executable, and had documented that this was its purpose.)
1 parent fc82e78 commit 588e6b0

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

gix-worktree-state/src/checkout/chunk.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ where
177177
// We process each key and do as the filter process tells us, while collecting data about the overall progress.
178178
let keys: BTreeSet<_> = delayed_filter_results.iter().map(|d| d.key.clone()).collect();
179179
let mut unknown_paths = Vec::new();
180-
let mut rela_path_as_path = Default::default();
181180
for key in keys {
182181
loop {
183182
let rela_paths = ctx.filters.driver_state_mut().list_delayed_paths(&key)?;
@@ -229,10 +228,7 @@ where
229228
entry::finalize_entry(
230229
delayed.entry,
231230
write.inner.into_inner().map_err(std::io::IntoInnerError::into_error)?,
232-
set_executable_after_creation.then(|| {
233-
rela_path_as_path = gix_path::from_bstr(delayed.entry_path);
234-
rela_path_as_path.as_ref()
235-
}),
231+
set_executable_after_creation,
236232
)?;
237233
delayed_files += 1;
238234
files.fetch_add(1, Ordering::Relaxed);

gix-worktree-state/src/checkout/entry.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ where
135135
};
136136

137137
// For possibly existing, overwritten files, we must change the file mode explicitly.
138-
finalize_entry(entry, file, set_executable_after_creation.then_some(dest))?;
138+
finalize_entry(entry, file, set_executable_after_creation)?;
139139
num_bytes
140140
}
141141
gix_index::entry::Mode::SYMLINK => {
@@ -275,16 +275,15 @@ pub(crate) fn open_file(
275275
try_op_or_unlink(path, overwrite_existing, |p| options.open(p)).map(|f| (f, set_executable_after_creation))
276276
}
277277

278-
/// Close `file` and store its stats in `entry`, possibly setting `file` executable depending on
279-
/// `set_executable_after_creation`.
278+
/// Close `file` and store its stats in `entry`, possibly setting `file` executable.
280279
pub(crate) fn finalize_entry(
281280
entry: &mut gix_index::Entry,
282281
file: std::fs::File,
283-
#[cfg_attr(windows, allow(unused_variables))] set_executable_after_creation: Option<&Path>,
282+
#[cfg_attr(windows, allow(unused_variables))] set_executable_after_creation: bool,
284283
) -> Result<(), crate::checkout::Error> {
285284
// For possibly existing, overwritten files, we must change the file mode explicitly.
286285
#[cfg(unix)]
287-
if let Some(path) = set_executable_after_creation {
286+
if set_executable_after_creation {
288287
set_executable(&file)?;
289288
}
290289
// NOTE: we don't call `file.sync_all()` here knowing that some filesystems don't handle this well.

0 commit comments

Comments
 (0)