mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Merge pull request #113575 from bruvzg/fix_path
[Unix] Remove leading `..` from absolute paths and apply `simplify_path` to Unix current directory path.
This commit is contained in:
@@ -4189,6 +4189,9 @@ String String::simplify_path() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vector<String> dirs = s.split("/", false);
|
Vector<String> dirs = s.split("/", false);
|
||||||
|
bool absolute_path = is_absolute_path();
|
||||||
|
|
||||||
|
absolute_path = absolute_path && !begins_with("res://"); // FIXME: Some code (GLTF importer) rely on accessing files up from `res://`, this probably should be disabled in the future.
|
||||||
|
|
||||||
for (int i = 0; i < dirs.size(); i++) {
|
for (int i = 0; i < dirs.size(); i++) {
|
||||||
String d = dirs[i];
|
String d = dirs[i];
|
||||||
@@ -4200,6 +4203,9 @@ String String::simplify_path() const {
|
|||||||
dirs.remove_at(i);
|
dirs.remove_at(i);
|
||||||
dirs.remove_at(i - 1);
|
dirs.remove_at(i - 1);
|
||||||
i -= 2;
|
i -= 2;
|
||||||
|
} else if (absolute_path && i == 0) {
|
||||||
|
dirs.remove_at(i);
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,10 @@
|
|||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
String DirAccessUnix::fix_path(const String &p_path) const {
|
||||||
|
return DirAccess::fix_path(p_path).simplify_path();
|
||||||
|
}
|
||||||
|
|
||||||
Error DirAccessUnix::list_dir_begin() {
|
Error DirAccessUnix::list_dir_begin() {
|
||||||
list_dir_end(); //close any previous dir opening!
|
list_dir_end(); //close any previous dir opening!
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ protected:
|
|||||||
String current_dir;
|
String current_dir;
|
||||||
virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); }
|
virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); }
|
||||||
virtual bool is_hidden(const String &p_name);
|
virtual bool is_hidden(const String &p_name);
|
||||||
|
virtual String fix_path(const String &p_path) const override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef void (*RemoveNotificationFunc)(const String &p_file);
|
typedef void (*RemoveNotificationFunc)(const String &p_file);
|
||||||
|
|||||||
Reference in New Issue
Block a user