From 9c4f7a2d3258d6e1348c3aeab97cc829d6ae920a Mon Sep 17 00:00:00 2001 From: "josh@gitbutler.com" Date: Tue, 19 Dec 2023 11:11:23 +0100 Subject: [PATCH] fix builds on windows --- packages/tauri/src/gb_repository/repository.rs | 2 +- packages/tauri/src/keys/controller.rs | 1 + packages/tauri/src/storage.rs | 14 +++++++++----- packages/tauri/src/virtual_branches/tests.rs | 1 + packages/tauri/src/virtual_branches/virtual.rs | 13 ++++++++++++- packages/tauri/src/windows.rs | 1 + 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/tauri/src/gb_repository/repository.rs b/packages/tauri/src/gb_repository/repository.rs index 6715dc04d..1f1408517 100644 --- a/packages/tauri/src/gb_repository/repository.rs +++ b/packages/tauri/src/gb_repository/repository.rs @@ -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::*; diff --git a/packages/tauri/src/keys/controller.rs b/packages/tauri/src/keys/controller.rs index 85063eae9..3f260c209 100644 --- a/packages/tauri/src/keys/controller.rs +++ b/packages/tauri/src/keys/controller.rs @@ -58,6 +58,7 @@ pub enum GetOrCreateError { Other(#[from] anyhow::Error), } +#[cfg(not(target_os = "windows"))] #[cfg(test)] mod tests { use std::fs; diff --git a/packages/tauri/src/storage.rs b/packages/tauri/src/storage.rs index 19ec26861..257e04ac2 100644 --- a/packages/tauri/src/storage.rs +++ b/packages/tauri/src/storage.rs @@ -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(()) } diff --git a/packages/tauri/src/virtual_branches/tests.rs b/packages/tauri/src/virtual_branches/tests.rs index ed8ab0ae9..e85086266 100644 --- a/packages/tauri/src/virtual_branches/tests.rs +++ b/packages/tauri/src/virtual_branches/tests.rs @@ -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, diff --git a/packages/tauri/src/virtual_branches/virtual.rs b/packages/tauri/src/virtual_branches/virtual.rs index b0bc0da2f..b38390d7b 100644 --- a/packages/tauri/src/virtual_branches/virtual.rs +++ b/packages/tauri/src/virtual_branches/virtual.rs @@ -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; } diff --git a/packages/tauri/src/windows.rs b/packages/tauri/src/windows.rs index 5db18691b..bf0e3ac95 100644 --- a/packages/tauri/src/windows.rs +++ b/packages/tauri/src/windows.rs @@ -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 }