1
0
Fork 0
mirror of synced 2024-04-27 09:12:06 +12:00

Add Windows support (#58)

This commit is contained in:
Rafał Mikrut 2020-10-10 15:18:04 +02:00 committed by GitHub
parent d001592c3f
commit d015b305f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 8 deletions

View file

@ -180,7 +180,8 @@ impl BigFile {
}
}
// Checking files
let current_file_name = "".to_owned()
#[allow(unused_mut)] // Used is later by Windows build
let mut current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
@ -194,6 +195,11 @@ impl BigFile {
}
}
#[cfg(target_family = "windows")]
{
current_file_name = Common::prettier_windows_path(&current_file_name);
}
// Creating new file entry
let fe: FileEntry = FileEntry {
path: current_file_name.clone(),

View file

@ -102,6 +102,10 @@ impl Common {
}
true
}
#[allow(clippy::ptr_arg)]
pub fn prettier_windows_path(path_to_change: &String) -> String {
path_to_change[..1].to_uppercase() + path_to_change[1..].to_lowercase().replace("\\", "/").as_str()
}
}
#[cfg(test)]
@ -128,4 +132,10 @@ mod test {
assert!(!Common::regex_check("*TTT", "/GGG"));
assert!(!Common::regex_check("AAA", "AAA"));
}
#[test]
fn test_windows_path() {
assert_eq!("C:/path.txt", Common::prettier_windows_path(&"c:/PATH.tXt".to_string()));
assert_eq!("H:/reka/weza/roman.txt", Common::prettier_windows_path(&"h:/RekA/Weza\\roMan.Txt".to_string()));
assert_eq!("T:/a", Common::prettier_windows_path(&"T:\\A".to_string()));
}
}

View file

@ -36,10 +36,16 @@ impl Directories {
text_messages.warnings.push("Included Directory Warning: Wildcards in path are not supported, ignoring ".to_string() + directory.as_str());
continue;
}
#[cfg(target_family = "unix")]
if !directory.starts_with('/') {
text_messages.warnings.push("Included Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
continue;
}
#[cfg(target_family = "windows")]
if !(directory[..directory.len()].starts_with(":/") || !directory[..directory.len()].starts_with(":\\")) {
text_messages.warnings.push("Included Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
continue;
}
if !Path::new(&directory).exists() {
text_messages.warnings.push("Included Directory Warning: Provided folder path must exits, ignoring ".to_string() + directory.as_str());
continue;
@ -80,7 +86,7 @@ impl Directories {
let mut checked_directories: Vec<String> = Vec::new();
for directory in directories {
let directory: String = directory.trim().to_string();
let directory: String = directory.trim().to_string().replace("\\", "/");
if directory == "" {
continue;
@ -93,12 +99,14 @@ impl Directories {
text_messages.warnings.push("Excluded Directory Warning: Wildcards in path are not supported, ignoring ".to_string() + directory.as_str());
continue;
}
#[cfg(target_family = "unix")]
if !directory.starts_with('/') {
text_messages.warnings.push("Excluded Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
continue;
}
if !Path::new(&directory).exists() {
text_messages.warnings.push("Excluded Directory Warning: Provided folder path must exits, ignoring ".to_string() + directory.as_str());
#[cfg(target_family = "windows")]
if !(directory[..directory.len()].starts_with(":/") || !directory[..directory.len()].starts_with(":\\")) {
text_messages.warnings.push("Excluded Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
continue;
}
if !Path::new(&directory).is_dir() {
@ -125,6 +133,13 @@ impl Directories {
let mut optimized_included: Vec<String> = Vec::<String>::new();
let mut optimized_excluded: Vec<String> = Vec::<String>::new();
// Windows(or specific EXT4 extension) doesn't recognize size of letters so we must remove one of directory e.g. - C:/h.txt, C:/H.txt
#[cfg(target_family = "windows")]
{
self.included_directories = self.included_directories.iter().map(Common::prettier_windows_path).collect();
self.excluded_directories = self.excluded_directories.iter().map(Common::prettier_windows_path).collect();
}
// Remove duplicated entries like: "/", "/"
self.excluded_directories.sort();

View file

@ -264,7 +264,8 @@ impl DuplicateFinder {
}
// Checking files
if metadata.len() >= self.minimal_file_size {
let current_file_name = "".to_owned()
#[allow(unused_mut)] // Used is later by Windows build
let mut current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
@ -278,6 +279,11 @@ impl DuplicateFinder {
}
}
#[cfg(target_family = "windows")]
{
current_file_name = Common::prettier_windows_path(&current_file_name);
}
// Creating new file entry
let fe: FileEntry = FileEntry {
path: current_file_name.clone(),

View file

@ -206,7 +206,8 @@ impl EmptyFiles {
}
// Checking files
if metadata.len() == 0 {
let current_file_name = "".to_owned()
#[allow(unused_mut)] // Used is later by Windows build
let mut current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
@ -219,6 +220,10 @@ impl EmptyFiles {
continue 'dir;
}
}
#[cfg(target_family = "windows")]
{
current_file_name = Common::prettier_windows_path(&current_file_name);
}
// Creating new file entry
let fe: FileEntry = FileEntry {

View file

@ -212,8 +212,14 @@ impl EmptyFolder {
}
// We need to set empty folder list
for (name, folder_entry) in folders_checked {
#[allow(unused_mut)] // Used is later by Windows build
for (mut name, folder_entry) in folders_checked {
if folder_entry.is_empty != FolderEmptiness::No {
#[cfg(target_family = "windows")]
{
name = Common::prettier_windows_path(&name);
}
self.empty_folder_list.insert(name, folder_entry);
}
}

View file

@ -128,6 +128,10 @@ impl Temporary {
}
current_folder = folders_to_check.pop().unwrap();
#[cfg(target_family = "windows")]
{
current_folder = Common::prettier_windows_path(&current_folder);
}
// Read current dir, if permission are denied just go to next
let read_dir = match fs::read_dir(&current_folder) {
Ok(t) => t,
@ -195,7 +199,8 @@ impl Temporary {
}
// Checking files
let current_file_name = "".to_owned()
#[allow(unused_mut)] // Used is later by Windows build
let mut current_file_name = "".to_owned()
+ &current_folder
+ match &entry_data.file_name().into_string() {
Ok(t) => t,
@ -209,6 +214,11 @@ impl Temporary {
}
}
#[cfg(target_family = "windows")]
{
current_file_name = Common::prettier_windows_path(&current_file_name);
}
// Creating new file entry
let fe: FileEntry = FileEntry {
path: current_file_name.clone(),