Add / to the unix shortcut drive list

Also made `get_current_drive()` to pick the longest match on Unix.

(cherry picked from commit 67f04b381b)
This commit is contained in:
Haoyu Qiu 2021-12-15 13:41:00 +08:00 committed by Rémi Verschelde
parent 8e29a37800
commit e40bb68c05
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 25 additions and 2 deletions

View file

@ -194,6 +194,8 @@ static bool _filter_drive(struct mntent *mnt) {
#endif
static void _get_drives(List<String> *list) {
list->push_back("/");
#if defined(HAVE_MNTENT) && defined(X11_ENABLED)
// Check /etc/mtab for the list of mounted partitions
FILE *mtab = setmntent("/etc/mtab", "r");
@ -262,6 +264,20 @@ String DirAccessUnix::get_drive(int p_drive) {
return list[p_drive];
}
int DirAccessUnix::get_current_drive() {
int drive = 0;
int max_length = -1;
const String path = get_current_dir().to_lower();
for (int i = 0; i < get_drive_count(); i++) {
const String d = get_drive(i).to_lower();
if (max_length < d.length() && path.begins_with(d)) {
max_length = d.length();
drive = i;
}
}
return drive;
}
bool DirAccessUnix::drives_are_shortcuts() {
return true;
}