Skip to content

Commit ef0f5f5

Browse files
author
Natan
committed
Adds FileType enum
1 parent 4b60d73 commit ef0f5f5

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

src-tauri/src/filesystem/cache.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::filesystem::{DIRECTORY, FILE};
1+
use crate::filesystem::FileType;
22
use crate::{AppState, CachedPath, StateSafe, VolumeCache};
33
use lazy_static::lazy_static;
44
use notify::event::{CreateKind, ModifyKind, RenameMode};
@@ -50,11 +50,10 @@ impl FsEventHandler {
5050

5151
let filename = path.file_name().unwrap().to_string_lossy().to_string();
5252
let file_type = match kind {
53-
CreateKind::File => FILE,
54-
CreateKind::Folder => DIRECTORY,
53+
CreateKind::File => FileType::File,
54+
CreateKind::Folder => FileType::Directory,
5555
_ => return, // Other options are weird lol
56-
}
57-
.to_string();
56+
};
5857

5958
let file_path = path.to_string_lossy().to_string();
6059
current_volume.entry(filename).or_insert_with(|| vec![CachedPath {
@@ -97,12 +96,12 @@ impl FsEventHandler {
9796
let current_volume = self.get_from_cache(state);
9897

9998
let filename = new_path.file_name().unwrap().to_string_lossy().to_string();
100-
let file_type = if new_path.is_dir() { DIRECTORY } else { FILE };
99+
let file_type = if new_path.is_dir() { FileType::Directory } else { FileType::File };
101100

102101
let path_string = new_path.to_string_lossy().to_string();
103102
current_volume.entry(filename).or_insert_with(|| vec![CachedPath {
104103
file_path: path_string,
105-
file_type: String::from(file_type),
104+
file_type: file_type,
106105
}]);
107106
}
108107

src-tauri/src/filesystem/explorer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::fs;
22
use std::fs::read_dir;
33
use std::ops::Deref;
4-
use std::path::{Path, PathBuf};
4+
use std::path::Path;
55
use notify::event::CreateKind;
66
use tauri::State;
77
use crate::errors::Error;
88
use crate::filesystem::cache::FsEventHandler;
9-
use crate::filesystem::fs_utils;
109
use crate::filesystem::fs_utils::get_mount_point;
1110
use crate::filesystem::volume::DirectoryChild;
1211
use crate::StateSafe;

src-tauri/src/filesystem/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
use serde::{Deserialize, Serialize};
2+
13
pub mod explorer;
24
pub mod cache;
35
pub mod volume;
46
mod fs_utils;
57

6-
pub const DIRECTORY: &str = "directory";
7-
pub const FILE: &str = "file";
8+
#[derive(Serialize, Deserialize, PartialEq)]
9+
pub enum FileType{
10+
Directory,
11+
File
12+
}
813

914
pub const fn bytes_to_gb(bytes: u64) -> u16 {
1015
(bytes / (1e+9 as u64)) as u16

src-tauri/src/filesystem/volume.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::filesystem::cache::{
22
load_system_cache, run_cache_interval, save_system_cache, FsEventHandler, CACHE_FILE_PATH,
33
};
4-
use crate::filesystem::{bytes_to_gb, DIRECTORY, FILE};
4+
use crate::filesystem::{bytes_to_gb, FileType};
55
use crate::{CachedPath, StateSafe};
66
use notify::{RecursiveMode, Watcher};
77
use rayon::prelude::*;
@@ -73,11 +73,10 @@ impl Volume {
7373

7474
let walkdir_filetype = entry.file_type();
7575
let file_type = if walkdir_filetype.is_dir() {
76-
DIRECTORY
76+
FileType::Directory
7777
} else {
78-
FILE
79-
}
80-
.to_string();
78+
FileType::File
79+
};
8180

8281
let cache_guard = &mut system_cache.lock().unwrap();
8382
cache_guard

src-tauri/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod filesystem;
55
mod search;
66
mod errors;
77

8+
use filesystem::FileType;
89
use filesystem::explorer::{open_file, open_directory, create_file, create_directory, rename_file, delete_file};
910
use filesystem::volume::get_volumes;
1011
use search::search_directory;
@@ -17,7 +18,7 @@ pub struct CachedPath {
1718
#[serde(rename = "p")]
1819
file_path: String,
1920
#[serde(rename = "t")]
20-
file_type: String,
21+
file_type: FileType,
2122
}
2223

2324
pub type VolumeCache = HashMap<String, Vec<CachedPath>>;

src-tauri/src/search.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::filesystem::volume::DirectoryChild;
2+
use crate::filesystem::FileType;
23
use crate::StateSafe;
34
use fuzzy_matcher::skim::SkimMatcherV2;
45
use fuzzy_matcher::FuzzyMatcher;
@@ -92,7 +93,7 @@ pub async fn search_directory(
9293
continue;
9394
}
9495

95-
if file_type == "file" {
96+
if *file_type == FileType::File {
9697
check_file(
9798
&matcher,
9899
accept_files,

0 commit comments

Comments
 (0)