|
41 | 41 | #include <sys/types.h> |
42 | 42 | #include <unistd.h> |
43 | 43 |
|
| 44 | +#if defined(TOOLS_ENABLED) |
| 45 | +#include <limits.h> |
| 46 | +#include <stdlib.h> |
| 47 | +#endif |
| 48 | + |
44 | 49 | void FileAccessUnix::check_errors() const { |
45 | 50 | ERR_FAIL_NULL_MSG(f, "File must be opened before use."); |
46 | 51 |
|
@@ -87,6 +92,22 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) { |
87 | 92 | } |
88 | 93 | } |
89 | 94 |
|
| 95 | +#if defined(TOOLS_ENABLED) |
| 96 | + if (p_mode_flags & READ) { |
| 97 | + String real_path = get_real_path(); |
| 98 | + if (real_path != path) { |
| 99 | + // Don't warn on symlinks, since they can be used to simply share addons on multiple projects. |
| 100 | + if (real_path.to_lower() == path.to_lower()) { |
| 101 | + // The File system is case insensitive, but other platforms can be sensitive to it |
| 102 | + // To ease cross-platform development, we issue a warning if users try to access |
| 103 | + // a file using the wrong case (which *works* on Windows and macOS, but won't on other |
| 104 | + // platforms). |
| 105 | + WARN_PRINT(vformat("Case mismatch opening requested file '%s', stored as '%s' in the filesystem. This file will not open when exported to other case-sensitive platforms.", path, real_path)); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +#endif |
| 110 | + |
90 | 111 | if (is_backup_save_enabled() && (p_mode_flags == WRITE)) { |
91 | 112 | save_path = path; |
92 | 113 | // Create a temporary file in the same directory as the target file. |
@@ -173,6 +194,26 @@ String FileAccessUnix::get_path_absolute() const { |
173 | 194 | return path; |
174 | 195 | } |
175 | 196 |
|
| 197 | +#if defined(TOOLS_ENABLED) |
| 198 | +String FileAccessUnix::get_real_path() const { |
| 199 | + char *resolved_path = ::realpath(path.utf8().get_data(), nullptr); |
| 200 | + |
| 201 | + if (!resolved_path) { |
| 202 | + return path; |
| 203 | + } |
| 204 | + |
| 205 | + String result; |
| 206 | + Error parse_ok = result.parse_utf8(resolved_path); |
| 207 | + ::free(resolved_path); |
| 208 | + |
| 209 | + if (parse_ok != OK) { |
| 210 | + return path; |
| 211 | + } |
| 212 | + |
| 213 | + return result.simplify_path(); |
| 214 | +} |
| 215 | +#endif |
| 216 | + |
176 | 217 | void FileAccessUnix::seek(uint64_t p_position) { |
177 | 218 | ERR_FAIL_NULL_MSG(f, "File must be opened before use."); |
178 | 219 |
|
|
0 commit comments