indexedlog: use fix_perm in more places

Summary:
This basically changes all places that indexedlog creates new files to use
the `fix_perm` utilities to fix permissions.

Reviewed By: xavierd

Differential Revision: D17870606

fbshipit-source-id: 164614bf70842f9e497148dd540ea861f2b5603d
This commit is contained in:
Jun Wu 2019-10-10 19:51:53 -07:00 committed by Facebook Github Bot
parent 9ae701065f
commit 09a7320221
4 changed files with 11 additions and 25 deletions

View File

@ -66,7 +66,7 @@ use crate::base16::{base16_to_base256, single_hex_to_base16, Base16Iter};
use crate::checksum_table::ChecksumTable;
use crate::errors::{IoResultExt, ResultExt};
use crate::lock::ScopedFileLock;
use crate::utils::{mmap_empty, mmap_readonly};
use crate::utils::{self, mmap_empty, mmap_readonly};
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use fs2::FileExt;
@ -1756,6 +1756,7 @@ impl OpenOptions {
if let Some(ref mut table) = checksum {
table.clear();
}
let _ = utils::fix_perm_file(&file, false);
let meta = Default::default();
(vec![MemRadix::default()], MemRoot { radix_offset, meta })
} else {

View File

@ -891,15 +891,7 @@ impl Log {
.write_file(&meta_path, self.open_options.fsync)
.context(|| format!(" before replacing index {:?})", name))?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
// https://github.com/Stebalien/tempfile/pull/61
let permissions = PermissionsExt::from_mode(0o664);
tmp.as_file()
.set_permissions(permissions)
.context(&tmp.path(), "cannot chmod")?;
}
let _ = utils::fix_perm_file(tmp.as_file(), false);
let path = dir.join(format!("{}{}", INDEX_FILE_PREFIX, name));
tmp.persist(&path).map_err(|e| {
@ -1212,6 +1204,7 @@ impl Log {
primary_file
.write_all(PRIMARY_HEADER)
.context(&primary_path, "cannot write")?;
let _ = utils::fix_perm_file(&primary_file, false);
// Start from empty file and indexes.
let meta = LogMetadata {
primary_len: PRIMARY_START_OFFSET,
@ -1831,6 +1824,7 @@ impl OpenOptions {
.context(&primary_path, "cannot open for write")?;
file.write_all(PRIMARY_HEADER)
.context(&primary_path, "cannot re-write header")?;
let _ = utils::fix_perm_file(&file, false);
message += "Fixed header in log\n";
}
Ok(())

View File

@ -152,17 +152,8 @@ pub fn atomic_write(
.sync_data()
.context(&file.path(), "cannot fdatasync")?;
}
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
// The tempfile crate is working on adding a way to do this automatically, until then, we
// need to do that by hand.
// https://github.com/Stebalien/tempfile/pull/61
let permissions = PermissionsExt::from_mode(0o664);
file.as_file()
.set_permissions(permissions)
.context(&file.path(), "cannot chmod")?;
}
// fix_perm issues are not fatal
let _ = fix_perm_file(file.as_file(), false);
let file = file
.persist(path)
.map_err(|e| crate::Error::wrap(Box::new(e), "cannot persist"))?;

View File

@ -80,8 +80,8 @@ new directories are setgid
00660 ./.hg/store/00changelog.i
00660 ./.hg/store/00manifest.i
02775 ./.hg/store/allheads/
00600 ./.hg/store/allheads/index-node
00600 ./.hg/store/allheads/log
00664 ./.hg/store/allheads/index-node
00664 ./.hg/store/allheads/log
00664 ./.hg/store/allheads/meta
00770 ./.hg/store/data/
00770 ./.hg/store/data/dir/
@ -134,8 +134,8 @@ XXX: treestate and allheads do not really respect this rule
00660 ../push/.hg/store/00changelog.i
00660 ../push/.hg/store/00manifest.i
02775 ../push/.hg/store/allheads/
00600 ../push/.hg/store/allheads/index-node
00600 ../push/.hg/store/allheads/log
00664 ../push/.hg/store/allheads/index-node
00664 ../push/.hg/store/allheads/log
00664 ../push/.hg/store/allheads/meta
00770 ../push/.hg/store/data/
00770 ../push/.hg/store/data/dir/