Add Windows support (#58)
This commit is contained in:
parent
d001592c3f
commit
d015b305f2
|
@ -180,7 +180,8 @@ impl BigFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Checking files
|
// Checking files
|
||||||
let current_file_name = "".to_owned()
|
#[allow(unused_mut)] // Used is later by Windows build
|
||||||
|
let mut current_file_name = "".to_owned()
|
||||||
+ ¤t_folder
|
+ ¤t_folder
|
||||||
+ match &entry_data.file_name().into_string() {
|
+ match &entry_data.file_name().into_string() {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
@ -194,6 +195,11 @@ impl BigFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
current_file_name = Common::prettier_windows_path(¤t_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
// Creating new file entry
|
// Creating new file entry
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
|
|
|
@ -102,6 +102,10 @@ impl Common {
|
||||||
}
|
}
|
||||||
true
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -128,4 +132,10 @@ mod test {
|
||||||
assert!(!Common::regex_check("*TTT", "/GGG"));
|
assert!(!Common::regex_check("*TTT", "/GGG"));
|
||||||
assert!(!Common::regex_check("AAA", "AAA"));
|
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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
text_messages.warnings.push("Included Directory Warning: Wildcards in path are not supported, ignoring ".to_string() + directory.as_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
if !directory.starts_with('/') {
|
if !directory.starts_with('/') {
|
||||||
text_messages.warnings.push("Included Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
|
text_messages.warnings.push("Included Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
|
||||||
continue;
|
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() {
|
if !Path::new(&directory).exists() {
|
||||||
text_messages.warnings.push("Included Directory Warning: Provided folder path must exits, ignoring ".to_string() + directory.as_str());
|
text_messages.warnings.push("Included Directory Warning: Provided folder path must exits, ignoring ".to_string() + directory.as_str());
|
||||||
continue;
|
continue;
|
||||||
|
@ -80,7 +86,7 @@ impl Directories {
|
||||||
let mut checked_directories: Vec<String> = Vec::new();
|
let mut checked_directories: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for directory in directories {
|
for directory in directories {
|
||||||
let directory: String = directory.trim().to_string();
|
let directory: String = directory.trim().to_string().replace("\\", "/");
|
||||||
|
|
||||||
if directory == "" {
|
if directory == "" {
|
||||||
continue;
|
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());
|
text_messages.warnings.push("Excluded Directory Warning: Wildcards in path are not supported, ignoring ".to_string() + directory.as_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
if !directory.starts_with('/') {
|
if !directory.starts_with('/') {
|
||||||
text_messages.warnings.push("Excluded Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
|
text_messages.warnings.push("Excluded Directory Warning: Relative path are not supported, ignoring ".to_string() + directory.as_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !Path::new(&directory).exists() {
|
#[cfg(target_family = "windows")]
|
||||||
text_messages.warnings.push("Excluded Directory Warning: Provided folder path must exits, ignoring ".to_string() + directory.as_str());
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if !Path::new(&directory).is_dir() {
|
if !Path::new(&directory).is_dir() {
|
||||||
|
@ -125,6 +133,13 @@ impl Directories {
|
||||||
let mut optimized_included: Vec<String> = Vec::<String>::new();
|
let mut optimized_included: Vec<String> = Vec::<String>::new();
|
||||||
let mut optimized_excluded: 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: "/", "/"
|
// Remove duplicated entries like: "/", "/"
|
||||||
|
|
||||||
self.excluded_directories.sort();
|
self.excluded_directories.sort();
|
||||||
|
|
|
@ -264,7 +264,8 @@ impl DuplicateFinder {
|
||||||
}
|
}
|
||||||
// Checking files
|
// Checking files
|
||||||
if metadata.len() >= self.minimal_file_size {
|
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()
|
||||||
+ ¤t_folder
|
+ ¤t_folder
|
||||||
+ match &entry_data.file_name().into_string() {
|
+ match &entry_data.file_name().into_string() {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
@ -278,6 +279,11 @@ impl DuplicateFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
current_file_name = Common::prettier_windows_path(¤t_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
// Creating new file entry
|
// Creating new file entry
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
|
|
|
@ -206,7 +206,8 @@ impl EmptyFiles {
|
||||||
}
|
}
|
||||||
// Checking files
|
// Checking files
|
||||||
if metadata.len() == 0 {
|
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()
|
||||||
+ ¤t_folder
|
+ ¤t_folder
|
||||||
+ match &entry_data.file_name().into_string() {
|
+ match &entry_data.file_name().into_string() {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
@ -219,6 +220,10 @@ impl EmptyFiles {
|
||||||
continue 'dir;
|
continue 'dir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
current_file_name = Common::prettier_windows_path(¤t_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
// Creating new file entry
|
// Creating new file entry
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
|
|
|
@ -212,8 +212,14 @@ impl EmptyFolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to set empty folder list
|
// 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 {
|
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);
|
self.empty_folder_list.insert(name, folder_entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,10 @@ impl Temporary {
|
||||||
}
|
}
|
||||||
current_folder = folders_to_check.pop().unwrap();
|
current_folder = folders_to_check.pop().unwrap();
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
current_folder = Common::prettier_windows_path(¤t_folder);
|
||||||
|
}
|
||||||
// Read current dir, if permission are denied just go to next
|
// Read current dir, if permission are denied just go to next
|
||||||
let read_dir = match fs::read_dir(¤t_folder) {
|
let read_dir = match fs::read_dir(¤t_folder) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
@ -195,7 +199,8 @@ impl Temporary {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking files
|
// Checking files
|
||||||
let current_file_name = "".to_owned()
|
#[allow(unused_mut)] // Used is later by Windows build
|
||||||
|
let mut current_file_name = "".to_owned()
|
||||||
+ ¤t_folder
|
+ ¤t_folder
|
||||||
+ match &entry_data.file_name().into_string() {
|
+ match &entry_data.file_name().into_string() {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
@ -209,6 +214,11 @@ impl Temporary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
current_file_name = Common::prettier_windows_path(¤t_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
// Creating new file entry
|
// Creating new file entry
|
||||||
let fe: FileEntry = FileEntry {
|
let fe: FileEntry = FileEntry {
|
||||||
path: current_file_name.clone(),
|
path: current_file_name.clone(),
|
||||||
|
|
Loading…
Reference in a new issue