comparison rust/hg-core/src/utils/files.rs @ 52552:66e34bc44280

rhg: set the expected temp file permissions (0o666 minus umask) This continues the theme of a48c688d3e80, and fixes the bug #6375, which was causing some problems for us, where a non-group-readable file can't be copied, which breaks some tools that copy the repo. This affects both the `checkexec` file and the temporary file we use for filesystem time measurement, since either of these files remaining on disk can cause this problem, and the 0666 permissions are just the better default here.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 05 Dec 2024 13:17:32 +0000
parents b55f653a0b34
children 94e2547e6f3d
comparison
equal deleted inserted replaced
52551:a0587c1b633a 52552:66e34bc44280
17 use lazy_static::lazy_static; 17 use lazy_static::lazy_static;
18 use same_file::is_same_file; 18 use same_file::is_same_file;
19 use std::ffi::{OsStr, OsString}; 19 use std::ffi::{OsStr, OsString};
20 use std::iter::FusedIterator; 20 use std::iter::FusedIterator;
21 use std::ops::Deref; 21 use std::ops::Deref;
22 use std::os::unix::fs::PermissionsExt;
22 use std::path::{Path, PathBuf}; 23 use std::path::{Path, PathBuf};
23 use std::{ 24 use std::{
24 borrow::{Cow, ToOwned}, 25 borrow::{Cow, ToOwned},
25 io, 26 io,
26 time::SystemTime, 27 time::SystemTime,
322 /// 323 ///
323 /// This may fail, typically if we lack write permissions. In that case we 324 /// This may fail, typically if we lack write permissions. In that case we
324 /// should continue the `status()` algoritm anyway and consider the current 325 /// should continue the `status()` algoritm anyway and consider the current
325 /// date/time to be unknown. 326 /// date/time to be unknown.
326 pub fn filesystem_now(repo_root: &Path) -> Result<SystemTime, io::Error> { 327 pub fn filesystem_now(repo_root: &Path) -> Result<SystemTime, io::Error> {
327 tempfile::tempfile_in(repo_root.join(".hg"))? 328 tempfile::Builder::new()
329 .permissions(std::fs::Permissions::from_mode(0o666))
330 .tempfile_in(repo_root.join(".hg"))?
331 .into_file()
328 .metadata()? 332 .metadata()?
329 .modified() 333 .modified()
330 } 334 }
331 335
332 #[cfg(test)] 336 #[cfg(test)]