review disk

This commit is contained in:
weisd
2024-09-24 00:00:44 +08:00
parent 6a3e01b3cc
commit 29100d5250
8 changed files with 265 additions and 49 deletions
+32 -1
View File
@@ -1,6 +1,11 @@
use std::{fs::Metadata, os::unix::fs::MetadataExt};
use std::{fs::Metadata, path::Path};
use tokio::{fs, io};
#[cfg(target_os = "linux")]
pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool {
use os::unix::fs::MetadataExt;
if f1.dev() != f2.dev() {
return false;
}
@@ -22,3 +27,29 @@ pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool {
true
}
#[cfg(target_os = "windows")]
pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool {
if f1.permissions() != f2.permissions() {
return false;
}
if f1.file_type() != f2.file_type() {
return false;
}
if f1.len() != f2.len() {
return false;
}
true
}
pub async fn access(path: impl AsRef<Path>) -> io::Result<()>{
fs::metadata(path).await?;
Ok(())
}
pub async fn make_dir_all(path: impl AsRef<Path>) -> io::Result<()>{
fs::create_dir_all(path.as_ref()).await
}
+1 -1
View File
@@ -1,6 +1,6 @@
const GLOBAL_DIR_SUFFIX: &str = "__XLDIR__";
const SLASH_SEPARATOR: &str = "/";
pub const SLASH_SEPARATOR: &str = "/";
pub fn has_suffix(s: &str, suffix: &str) -> bool {
if cfg!(target_os = "windows") {