Skip to content

Commit 72e6538

Browse files
ryanabxmmstick
authored andcommitted
fix: Iter goes through directories in proper order
Since Iter is supposed to go through the directories in the order that they are specified, we need to remove entries from the front of the list, not the back.
1 parent 973c5ad commit 72e6538

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/iter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ impl Iterator for Iter {
2525
let mut iterator = match self.actively_walking.take() {
2626
Some(dir) => dir,
2727
None => {
28-
while let Some(path) = self.directories_to_walk.pop() {
28+
while !self.directories_to_walk.is_empty() {
29+
let path = self.directories_to_walk.remove(0);
2930
match fs::read_dir(&path) {
3031
Ok(directory) => {
3132
self.actively_walking = Some(directory);
@@ -47,7 +48,7 @@ impl Iterator for Iter {
4748

4849
if let Ok(file_type) = entry.file_type() {
4950
if file_type.is_dir() {
50-
self.directories_to_walk.push(path);
51+
self.directories_to_walk.insert(0, path);
5152
} else if (file_type.is_file() || file_type.is_symlink())
5253
&& path.extension().map_or(false, |ext| ext == "desktop")
5354
{

src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ pub enum PathSource {
288288
}
289289

290290
impl PathSource {
291-
292291
/// Attempts to determine the PathSource for a given Path.
293292
/// Note that this is a best-effort guesting function, and its results should be treated as
294293
/// such (e.g.: non-canonical).
@@ -304,15 +303,19 @@ impl PathSource {
304303
PathSource::SystemFlatpak
305304
} else if path.starts_with("/var/lib/snapd") {
306305
PathSource::SystemSnap
307-
} else if path.starts_with("/nix/var/nix/profiles/default") || path.starts_with("/nix/store") {
306+
} else if path.starts_with("/nix/var/nix/profiles/default")
307+
|| path.starts_with("/nix/store")
308+
{
308309
PathSource::Nix
309310
} else if path.to_string_lossy().contains("/flatpak/") {
310311
PathSource::LocalFlatpak
311312
} else if path.starts_with(&data_home.as_path()) {
312313
PathSource::Local
313-
} else if path.starts_with("/nix/var/nix/profiles/per-user") || path.to_string_lossy().contains(".nix") {
314+
} else if path.starts_with("/nix/var/nix/profiles/per-user")
315+
|| path.to_string_lossy().contains(".nix")
316+
{
314317
PathSource::LocalNix
315-
} else {
318+
} else {
316319
PathSource::Other(String::from("unknown"))
317320
}
318321
}

0 commit comments

Comments
 (0)