Skip to content

Commit f0e18a0

Browse files
authored
Merge pull request #7 from visnkmr/v0.23
V0.23
2 parents 0e00082 + ed40288 commit f0e18a0

13 files changed

+307
-171
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "filedime",
3-
"version": "0.22.2",
3+
"version": "0.23.0",
44
"private": true,
55
"devDependencies": {
66
"@rspack/cli": "^0.1.10",

src-tauri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ image = "0.24.6"
3434
# image = {git="https://codeberg.org/visnk/image-rs.git"}
3535

3636
fuzzy-matcher="0.3.7"
37-
37+
num_cpus="1.15.0"
3838
rustc-hash="1.1.0"
3939
# tao = { version = "0.19.0"}
4040
# du="0.1.1"

src-tauri/src/filltrie.rs

Lines changed: 186 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{path::{PathBuf, Path}, time::{SystemTime, UNIX_EPOCH, Instant, Duration}, fs::{self, File}, sync::{Arc, Mutex, RwLock, atomic::{Ordering, AtomicBool}}, thread, io::{BufReader, BufRead}, collections::{HashSet, HashMap}};
22

3-
use ignore::{Walk, WalkBuilder};
3+
use ignore::{Walk, WalkBuilder, WalkState};
44
use rayon::prelude::*;
55
use serde_json::json;
66
use tauri::{Window, State, Manager};
@@ -79,131 +79,203 @@ pub async fn populate_try(path: String, window:&Window,state: &State<'_, AppStat
7979
// let st=state.searchtry.clone();
8080

8181
// move||{
82-
let walker2 =
83-
WalkBuilder::new(&path)
84-
.hidden(true) // Include hidden files and directories
85-
.follow_links(false)
86-
.parents(true)
87-
.git_exclude(true)
88-
.ignore(true) // Disable the default ignore rules
89-
.git_ignore(true) // Respect the .gitignore file
90-
.build();
91-
// WalkDir::new(&path)
92-
// .contents_first(true)
93-
// .min_depth(1) // skip the root directory
94-
// // .max_depth(1) // only look at the immediate subdirectories
95-
// .into_iter()
82+
let threads = (num_cpus::get() as f64 * 0.75).round() as usize;
83+
84+
WalkBuilder::new(&path)
85+
.threads(threads)
86+
.hidden(true) // Include hidden files and directories
87+
.follow_links(false)
88+
// .threads(n)
89+
.parents(true)
90+
.git_exclude(true)
91+
.ignore(true) // Disable the default ignore rules
92+
.git_ignore(true) // Respect the .gitignore file
93+
.build_parallel()
94+
.run(|| {
95+
println!("Populating");
96+
97+
// let total_bytes = total_bytes.clone();
98+
// let database = database.clone();
99+
// let root = root.as_ref().to_owned();
100+
Box::new(move |entry| {
101+
match(entry){
102+
Ok(e)=>{
103+
if let Some(eft)=(e.file_type()){
104+
105+
if(!eft.is_dir())
106+
{
107+
108+
// println!("{:?}",e.path());
109+
// }
110+
let i = e.path().to_string_lossy().to_string();
111+
let name=e.file_name().to_string_lossy().to_string().to_lowercase();
112+
let map=state.stl.clone();
113+
let mut map =map.lock().unwrap();
114+
if let Some(hs) = map.get_mut(&name) {
115+
// If yes, append the value to the existing vector
116+
// if(!hs.contains(&i)){
117+
hs.insert(i);
118+
// }
119+
} else {
120+
// If no, create a new vector with the value and insert it into the hashmap
121+
map.insert(name, HashSet::from_iter(vec![i]));
122+
}
123+
// map.entry(name).or_insert(Vec::new()).push(i);
124+
}
125+
}
126+
},
127+
Err(_)=>{
128+
129+
}
130+
}
131+
// if *state.process_count.lock().unwrap() != orig { // check if the current count value is different from the original one
132+
// return ; // if yes, it means a new command has been invoked and the old one should be canceled
133+
// }
134+
// println!("{:?}",e.path());
135+
136+
// if entry.file_type().map_or(false, |t| t.is_file()) {
137+
// let metrics = compute_metrics(entry.path(), features).unwrap(); // ?
138+
// *total_bytes.lock().unwrap() += metrics.size;
139+
// let result = Entry::File(metrics);
140+
// let short_path = if entry.path() == root {
141+
// Path::new(entry.path().file_name().expect("unreachable"))
142+
// } else {
143+
// entry.path().strip_prefix(&root).unwrap() // ?
144+
// };
145+
// database
146+
// .lock()
147+
// .unwrap()
148+
// .insert(short_path.to_owned(), result);
149+
// }
150+
WalkState::Continue
151+
})
152+
});
153+
// let walker2 =
154+
// WalkBuilder::new(&path)
155+
// .hidden(true) // Include hidden files and directories
156+
// .follow_links(false)
157+
// // .threads(n)
158+
// .parents(true)
159+
// .git_exclude(true)
160+
// .ignore(true) // Disable the default ignore rules
161+
// .git_ignore(true) // Respect the .gitignore file
162+
// .build();
163+
// // WalkDir::new(&path)
164+
// // .contents_first(true)
165+
// // .min_depth(1) // skip the root directory
166+
// // // .max_depth(1) // only look at the immediate subdirectories
167+
// // .into_iter()
96168

97-
// .filter_entry(
98-
// |e|
99-
// !e.path_is_symlink()
100-
// // &&
101-
// // !e
102-
// // .file_name()
103-
// // .to_str()
104-
// // .map(|s| s.starts_with("."))
105-
// // .unwrap_or(false)
106-
// &&
107-
// !is_hidden(e)
108-
// // &&
109-
// // e.file_type().is_file()
110-
// // e.file_type().is_dir()
111-
// );
169+
// // .filter_entry(
170+
// // |e|
171+
// // !e.path_is_symlink()
172+
// // // &&
173+
// // // !e
174+
// // // .file_name()
175+
// // // .to_str()
176+
// // // .map(|s| s.starts_with("."))
177+
// // // .unwrap_or(false)
178+
// // &&
179+
// // !is_hidden(e)
180+
// // // &&
181+
// // // e.file_type().is_file()
182+
// // // e.file_type().is_dir()
183+
// // );
112184

113-
let mut count=RwLock::new(0);
114-
set_enum_value(&state.whichthread, wThread::Populating);
115-
let stop_flag_local = Arc::new(AtomicBool::new(true));
185+
// let mut count=RwLock::new(0);
186+
// set_enum_value(&state.whichthread, wThread::Populating);
187+
// let stop_flag_local = Arc::new(AtomicBool::new(true));
116188

117-
let par_walker2 = walker2;
118-
// .par_bridge(); // ignore errors
189+
// let par_walker2 = walker2;
190+
// // .par_bridge(); // ignore errors
119191

120-
// let k:HashSet<String>=
121-
// let paths:Vec<String>=
122-
par_walker2
192+
// // let k:HashSet<String>=
193+
// // let paths:Vec<String>=
194+
// par_walker2
123195

124-
// .enumerate()
125-
// .into_par_iter()
126-
.filter(|(_)|{
196+
// // .enumerate()
197+
// // .into_par_iter()
198+
// .filter(|(_)|{
127199

128-
let local_thread_controller=stop_flag_local.clone();
129-
if(!local_thread_controller.load(Ordering::SeqCst)){
130-
eprintln!("thread stopped by local controller");
131-
return false;
132-
}
133-
// println!("{:?}",get_enum_value(&state.whichthread) );
200+
// let local_thread_controller=stop_flag_local.clone();
201+
// if(!local_thread_controller.load(Ordering::SeqCst)){
202+
// eprintln!("thread stopped by local controller");
203+
// return false;
204+
// }
205+
// // println!("{:?}",get_enum_value(&state.whichthread) );
134206

135-
if let wThread::Populating = get_enum_value(&state.whichthread)
136-
{
137-
// eprintln!("addedtosearch");
138-
}
139-
else
140-
{
141-
local_thread_controller.store(false, Ordering::SeqCst);
142-
eprintln!("thread stopped by global controller");
143-
return false;
144-
}
145-
return true;
146-
})
147-
.filter_map(Result::ok)
148-
.for_each(
149-
|e|
150-
{
151-
// thread::sleep(Duration::from_secs(1));
152-
println!("Populating");
153-
// let local_thread_controller=stop_flag_local.clone();
154-
// if(!local_thread_controller.load(Ordering::SeqCst)){
155-
// eprintln!("thread stopped by local controller");
156-
// return ;
157-
// }
158-
// if let wThread::Populating = get_enum_value(&state.whichthread)
159-
// { eprintln!("addedtosearch");}
160-
// else
161-
// {
162-
// local_thread_controller.store(false, Ordering::SeqCst);
163-
// eprintln!("thread stopped by global controller");
164-
// return ;
165-
// }
166-
// return true;
207+
// if let wThread::Populating = get_enum_value(&state.whichthread)
208+
// {
209+
// // eprintln!("addedtosearch");
210+
// }
211+
// else
212+
// {
213+
// local_thread_controller.store(false, Ordering::SeqCst);
214+
// eprintln!("thread stopped by global controller");
215+
// return false;
216+
// }
217+
// return true;
218+
// })
219+
// .filter_map(Result::ok)
220+
// .for_each(
221+
// |e|
222+
// {
223+
// // thread::sleep(Duration::from_secs(1));
224+
// println!("Populating");
225+
// // let local_thread_controller=stop_flag_local.clone();
226+
// // if(!local_thread_controller.load(Ordering::SeqCst)){
227+
// // eprintln!("thread stopped by local controller");
228+
// // return ;
229+
// // }
230+
// // if let wThread::Populating = get_enum_value(&state.whichthread)
231+
// // { eprintln!("addedtosearch");}
232+
// // else
233+
// // {
234+
// // local_thread_controller.store(false, Ordering::SeqCst);
235+
// // eprintln!("thread stopped by global controller");
236+
// // return ;
237+
// // }
238+
// // return true;
167239

168-
// window.emit("reloadlist",json!({
169-
// "message": "pariter5",
170-
// "status": "running",
171-
// }));
172-
if *state.process_count.lock().unwrap() != orig { // check if the current count value is different from the original one
173-
return ; // if yes, it means a new command has been invoked and the old one should be canceled
174-
}
175-
// println!("{:?}",e.path());
176-
if let Some(eft)=(e.file_type()){
240+
// // window.emit("reloadlist",json!({
241+
// // "message": "pariter5",
242+
// // "status": "running",
243+
// // }));
244+
// if *state.process_count.lock().unwrap() != orig { // check if the current count value is different from the original one
245+
// return ; // if yes, it means a new command has been invoked and the old one should be canceled
246+
// }
247+
// // println!("{:?}",e.path());
248+
// if let Some(eft)=(e.file_type()){
177249

178-
if(!eft.is_dir())
179-
{
250+
// if(!eft.is_dir())
251+
// {
180252

181-
// println!("{:?}",e.path());
182-
// }
183-
let i = e.path().to_string_lossy().to_string();
184-
let name=e.file_name().to_string_lossy().to_string().to_lowercase();
185-
let map=state.stl.clone();
186-
let mut map =map.lock().unwrap();
187-
if let Some(hs) = map.get_mut(&name) {
188-
// If yes, append the value to the existing vector
189-
// if(!hs.contains(&i)){
190-
hs.insert(i);
191-
// }
192-
} else {
193-
// If no, create a new vector with the value and insert it into the hashmap
194-
map.insert(name, HashSet::from_iter(vec![i]));
195-
}
196-
// map.entry(name).or_insert(Vec::new()).push(i);
197-
}
198-
}
199-
// return true; // e.path().to_string_lossy().to_string()
200-
}
201-
);
253+
// // println!("{:?}",e.path());
254+
// // }
255+
// let i = e.path().to_string_lossy().to_string();
256+
// let name=e.file_name().to_string_lossy().to_string().to_lowercase();
257+
// let map=state.stl.clone();
258+
// let mut map =map.lock().unwrap();
259+
// if let Some(hs) = map.get_mut(&name) {
260+
// // If yes, append the value to the existing vector
261+
// // if(!hs.contains(&i)){
262+
// hs.insert(i);
263+
// // }
264+
// } else {
265+
// // If no, create a new vector with the value and insert it into the hashmap
266+
// map.insert(name, HashSet::from_iter(vec![i]));
267+
// }
268+
// // map.entry(name).or_insert(Vec::new()).push(i);
269+
// }
270+
// }
271+
// // return true; // e.path().to_string_lossy().to_string()
272+
// }
273+
// );
202274
// .collect();
203275
// state.st.lock().unwrap().populate_trie(paths);
204-
if(!stop_flag_local.load(Ordering::SeqCst)){
205-
return Ok(())
206-
}
276+
// if(!stop_flag_local.load(Ordering::SeqCst)){
277+
// return Ok(())
278+
// }
207279
let now = SystemTime::now();
208280
let duration = now.duration_since(UNIX_EPOCH).unwrap();
209281
let endtime = duration.as_secs();

src-tauri/src/listfiles.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ let stop_flag_local = Arc::new(AtomicBool::new(true));
414414
// println!("{:?}",serde_json::to_string(&files.clone()).unwrap());
415415
stoptimer(&wname,&app_handle)?;
416416

417-
if(*state.loadsearchlist.read().unwrap()){
417+
// if(*state.loadsearchlist.read().unwrap()){
418418
populate_try(path, &window,&state).await;
419-
}
419+
// }
420420

421421
let now = SystemTime::now();
422422
let duration = now.duration_since(UNIX_EPOCH).unwrap();

0 commit comments

Comments
 (0)