Skip to content

Commit

Permalink
Fixed some compilation errors for Windows and fixed clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kinire98 committed Jan 24, 2024
1 parent 83e5cc6 commit ecb184a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::*;

use crate::sys::should_be_backed;
#[cfg(unix)]
use crate::sys::unix::*;
use fs_extra::copy_items;
Expand All @@ -14,29 +14,27 @@ use std::path::{Path, PathBuf};

pub fn backup(origin_dir: PathBuf, target_dir: PathBuf) -> Result<()> {
let path_target_dir: Box<Path> = target_dir.clone().into();
if let None = path_target_dir.read_dir().unwrap().next() {
/*match std::fs::copy(origin_dir, target_dir) {
if path_target_dir.read_dir().unwrap().next().is_none() {
let dir: Box<Path> = origin_dir.into();
match copy_items(&[dir], target_dir, &fs_extra::dir::CopyOptions::default()) {
Ok(_) => return Ok(()),
Err(_) => {
return Err(Error {
kind: ErrorKind::FSError,
})
}
}*/
let path: Box<Path> = origin_dir.into();
let _ = copy_items(&[path], target_dir, &fs_extra::dir::CopyOptions::default()).unwrap();
return Ok(());
}
}

// Some testing :)
/*println!("origin_dir: {} ", origin_dir.display());
println!("origin_dir: {} ", origin_dir.display());
println!("target_dir: {} ", target_dir.display());
println!(
"Should be backed: {}",
should_be_backed(
<PathBuf as TryInto<OsType>>::try_into(origin_dir).unwrap(),
<PathBuf as TryInto<OsType>>::try_into(target_dir).unwrap()
)
);*/
);
Ok(())
}
12 changes: 6 additions & 6 deletions src/sys.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::error::{Error, ErrorKind};

pub fn should_be_backed(file_to_backup: impl File, already_backed_file: impl File) -> bool {
#[cfg(windows)]
if file_to_backup.is_folder() {
Expand All @@ -19,8 +17,9 @@ trait File {
}
#[cfg(windows)]
pub mod windows {
use crate::error::{Error, ErrorKind};
use std::fs;
use std::os::windows::MetadataExt;
use std::os::windows::prelude::MetadataExt;
use std::path::{Path, PathBuf};

pub struct WindowsFileTime {
Expand All @@ -36,7 +35,7 @@ pub mod windows {
}
}
impl TryFrom<PathBuf> for WindowsFileTime {
type Error = Error;
type Error = crate::error::Error;
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
let path: Box<Path> = value.into();
let metadata = match fs::metadata(value) {
Expand All @@ -56,6 +55,7 @@ pub mod windows {
}
#[cfg(unix)]
pub mod unix {
use crate::error::{Error, ErrorKind};
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::path::PathBuf;
Expand All @@ -71,8 +71,8 @@ pub mod unix {
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
match fs::metadata(value) {
Ok(file_metadata) => Ok(UnixFileTime(file_metadata.mtime())),
Err(_) => Err(super::Error {
kind: super::ErrorKind::FSError,
Err(_) => Err(Error {
kind: ErrorKind::FSError,
}),
}
}
Expand Down

0 comments on commit ecb184a

Please sign in to comment.