Merge pull request #2098 from gitbutlerapp/add-windows-metadata-shim

Add windows metadata shim
This commit is contained in:
Qix 2023-12-19 10:47:11 +01:00 committed by GitHub
commit 807aa56e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,8 @@ use std::{
path, time,
};
#[cfg(target_os = "windows")]
use crate::windows::*;
#[cfg(target_family = "unix")]
use std::os::unix::prelude::*;

View File

@ -1,4 +1,5 @@
#![feature(error_generic_member_access)]
#![cfg_attr(target_os = "windows", feature(windows_by_handle))]
pub mod analytics;
pub mod app;
@ -29,6 +30,8 @@ pub mod types;
pub mod users;
pub mod virtual_branches;
pub mod watcher;
#[cfg(target_os = "windows")]
pub(crate) mod windows;
pub mod writer;
pub mod zip;

View File

@ -0,0 +1,23 @@
use std::os::windows::fs::MetadataExt;
pub trait MetadataShim {
fn ino(&self) -> u64;
fn dev(&self) -> u64;
fn uid(&self) -> u32;
fn gid(&self) -> u32;
}
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)")
}
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
}
fn uid(&self) -> u32 {
0
}
fn gid(&self) -> u32 {
0
}
}