mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-30 20:09:50 +03:00
Merge pull request #2099 from gitbutlerapp/set-user-permissions-on-unix
Set user permissions on unix
This commit is contained in:
commit
6deff6f4c2
@ -6,7 +6,7 @@ use std::{
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use crate::windows::*;
|
||||
use crate::windows::MetadataShim;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::prelude::*;
|
||||
|
||||
|
@ -58,6 +58,7 @@ pub enum GetOrCreateError {
|
||||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
@ -58,11 +58,15 @@ impl Storage {
|
||||
}
|
||||
fs::write(&file_path, content).map_err(Error::IO)?;
|
||||
|
||||
// Set the permissions to be user-only.
|
||||
let metadata = fs::metadata(file_path.clone())?;
|
||||
let mut permissions = metadata.permissions();
|
||||
permissions.set_mode(0o600); // User read/write
|
||||
fs::set_permissions(file_path.clone(), permissions)?;
|
||||
// Set the permissions to be user-only. We can't actually
|
||||
// do this on Windows, so we ignore that platform.
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
let metadata = fs::metadata(file_path.clone())?;
|
||||
let mut permissions = metadata.permissions();
|
||||
permissions.set_mode(0o600); // User read/write
|
||||
fs::set_permissions(file_path.clone(), permissions)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -2312,6 +2312,7 @@ fn test_commit_add_and_delete_files() -> Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_family = "unix")]
|
||||
fn test_commit_executable_and_symlinks() -> Result<()> {
|
||||
let Case {
|
||||
project_repository,
|
||||
|
@ -1905,9 +1905,20 @@ pub fn write_tree_onto_commit(
|
||||
let mut filemode = git::FileMode::Blob;
|
||||
// check if full_path file is executable
|
||||
if let Ok(metadata) = std::fs::symlink_metadata(&full_path) {
|
||||
if metadata.permissions().mode() & 0o111 != 0 {
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
if metadata.permissions().mode() & 0o111 != 0 {
|
||||
filemode = git::FileMode::BlobExecutable;
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
// TODO(qix-): Pull from `core.filemode` config option to determine
|
||||
// TODO(qix-): the behavior on windows. For now, we set this to true.
|
||||
// TODO(qix-): It's not ideal, but it gets us to a windows build faster.
|
||||
filemode = git::FileMode::BlobExecutable;
|
||||
}
|
||||
|
||||
if metadata.file_type().is_symlink() {
|
||||
filemode = git::FileMode::Link;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ impl MetadataShim for std::fs::Metadata {
|
||||
fn ino(&self) -> u64 {
|
||||
self.file_index().expect("file metadata constructed based on directory listing instead of a file (see https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html#tymethod.file_index)")
|
||||
}
|
||||
#[allow(clippy::cast_lossless)]
|
||||
fn dev(&self) -> u64 {
|
||||
self.volume_serial_number().expect("file metadata constructed based on directory listing instead of a file (see https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html#tymethod.volume_serial_number)") as u64
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user