mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
vfs: add set_executable api
Summary: set_executable is a pub function of VFS that set exec permissions on simple file Reviewed By: quark-zju Differential Revision: D26212713 fbshipit-source-id: 4c3ef477fc8d61362285654dda0b006342e046ee
This commit is contained in:
parent
199f1cc1b9
commit
9a89bd4057
@ -119,16 +119,21 @@ impl VFS {
|
||||
/// Write an executable file with `content` as `filepath`.
|
||||
fn write_executable(&self, filepath: &Path, content: &Bytes) -> Result<usize> {
|
||||
let size = self.write_regular(filepath, content)?;
|
||||
self.set_exec(filepath, true)?;
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
fn set_exec(&self, filepath: &Path, flag: bool) -> Result<()> {
|
||||
#[cfg(windows)]
|
||||
return Ok(size);
|
||||
return Ok(());
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let perms = Permissions::from_mode(0o755);
|
||||
let mode = if flag { 0o755 } else { 0o644 };
|
||||
let perms = Permissions::from_mode(mode);
|
||||
set_permissions(filepath, perms)
|
||||
.with_context(|| format!("Can't set {:?} as executable", filepath))?;
|
||||
Ok(size)
|
||||
.with_context(|| format!("Can't update exec flag({}) on {:?}", flag, filepath))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,6 +187,15 @@ impl VFS {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_executable(&self, path: &RepoPath, flag: bool) -> Result<()> {
|
||||
let filepath = self
|
||||
.auditor
|
||||
.audit(path)
|
||||
.with_context(|| format!("Can't write into {}", path))?;
|
||||
|
||||
self.set_exec(&filepath, flag)
|
||||
}
|
||||
|
||||
/// Remove the file at `path`.
|
||||
///
|
||||
/// The parent directories of this file will be removed recursively if they are empty.
|
||||
|
Loading…
Reference in New Issue
Block a user