Skip to content

Commit 4dc57be

Browse files
KixironJoshua Nelson
authored and
Joshua Nelson
committed
Reverted file sorting
1 parent 38d6f48 commit 4dc57be

File tree

1 file changed

+39
-41
lines changed

1 file changed

+39
-41
lines changed

src/web/source.rs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -104,48 +104,49 @@ impl FileList {
104104

105105
let files: Value = rows.get(0).get_opt(5).unwrap().ok()?;
106106

107+
let mut file_list = Vec::new();
107108
if let Some(files) = files.as_array() {
108-
let mut file_list: Vec<File> = files
109-
.iter()
110-
.filter_map(|file| {
111-
if let Some(file) = file.as_array() {
112-
let mime = file[0].as_str().unwrap();
113-
let path = file[1].as_str().unwrap();
114-
115-
// skip .cargo-ok generated by cargo
116-
if path == ".cargo-ok" {
117-
return None;
118-
}
109+
file_list.reserve(files.len());
119110

120-
// look only files for req_path
121-
if path.starts_with(&req_path) {
122-
// remove req_path from path to reach files in this directory
123-
let path = path.replace(&req_path, "");
124-
let path_splited: Vec<&str> = path.split('/').collect();
125-
126-
// if path have '/' it is a directory
127-
let ftype = if path_splited.len() > 1 {
128-
FileType::Dir
129-
} else if mime.starts_with("text") && path_splited[0].ends_with(".rs") {
130-
FileType::RustSource
131-
} else if mime.starts_with("text") {
132-
FileType::Text
133-
} else {
134-
FileType::Binary
135-
};
136-
137-
let file = File {
138-
name: path_splited[0].to_owned(),
139-
file_type: ftype,
140-
};
141-
142-
return Some(file);
143-
}
111+
for file in files {
112+
if let Some(file) = file.as_array() {
113+
let mime = file[0].as_str().unwrap();
114+
let path = file[1].as_str().unwrap();
115+
116+
// skip .cargo-ok generated by cargo
117+
if path == ".cargo-ok" {
118+
return None;
144119
}
145120

146-
None
147-
})
148-
.collect::<Vec<_>>();
121+
// look only files for req_path
122+
if path.starts_with(&req_path) {
123+
// remove req_path from path to reach files in this directory
124+
let path = path.replace(&req_path, "");
125+
let path_splited: Vec<&str> = path.split('/').collect();
126+
127+
// if path have '/' it is a directory
128+
let ftype = if path_splited.len() > 1 {
129+
FileType::Dir
130+
} else if mime.starts_with("text") && path_splited[0].ends_with(".rs") {
131+
FileType::RustSource
132+
} else if mime.starts_with("text") {
133+
FileType::Text
134+
} else {
135+
FileType::Binary
136+
};
137+
138+
let file = File {
139+
name: path_splited[0].to_owned(),
140+
file_type: ftype,
141+
};
142+
143+
// avoid adding duplicates, a directory may occur more than once
144+
if !file_list.contains(&file) {
145+
file_list.push(file);
146+
}
147+
}
148+
}
149+
}
149150

150151
if file_list.is_empty() {
151152
return None;
@@ -162,9 +163,6 @@ impl FileList {
162163
}
163164
});
164165

165-
// avoid adding duplicates, a directory may occur more than once
166-
file_list.dedup();
167-
168166
Some(FileList {
169167
metadata: MetaData {
170168
name: rows.get(0).get(0),

0 commit comments

Comments
 (0)