|
8 | 8 | #include <Shlwapi.h> |
9 | 9 | #include <fcntl.h> |
10 | 10 | #include <limits.h> |
11 | | -#include <sys/stat.h> |
12 | 11 |
|
13 | 12 | #include <algorithm> |
14 | 13 | #include <sstream> |
|
18 | 17 | #include "flutter/fml/platform/win/errors_win.h" |
19 | 18 | #include "flutter/fml/platform/win/wstring_conversion.h" |
20 | 19 |
|
21 | | -#if defined(OS_WIN) |
22 | | -#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) |
23 | | -#endif |
24 | | - |
25 | 20 | namespace fml { |
26 | 21 |
|
27 | 22 | static std::string GetFullHandlePath(const fml::UniqueFD& handle) { |
@@ -80,6 +75,16 @@ static DWORD GetShareFlags(FilePermission permission) { |
80 | 75 | return FILE_SHARE_READ; |
81 | 76 | } |
82 | 77 |
|
| 78 | +static DWORD GetFileAttributesForUtf8Path(const char* absolute_path) { |
| 79 | + return ::GetFileAttributes(ConvertToWString(absolute_path).c_str()); |
| 80 | +} |
| 81 | + |
| 82 | +static DWORD GetFileAttributesForUtf8Path(const fml::UniqueFD& base_directory, |
| 83 | + const char* path) { |
| 84 | + std::string full_path = GetFullHandlePath(base_directory) + "\\" + path; |
| 85 | + return GetFileAttributesForUtf8Path(full_path.c_str()); |
| 86 | +} |
| 87 | + |
83 | 88 | std::string CreateTemporaryDirectory() { |
84 | 89 | // Get the system temporary directory. |
85 | 90 | auto temp_dir_container = GetTemporaryDirectoryPath(); |
@@ -253,16 +258,17 @@ bool IsDirectory(const fml::UniqueFD& directory) { |
253 | 258 | } |
254 | 259 |
|
255 | 260 | bool IsDirectory(const fml::UniqueFD& base_directory, const char* path) { |
256 | | - std::string full_path = GetFullHandlePath(base_directory) + "\\" + path; |
257 | | - return ::GetFileAttributes(ConvertToWString(full_path.c_str()).c_str()) & |
| 261 | + return GetFileAttributesForUtf8Path(base_directory, path) & |
258 | 262 | FILE_ATTRIBUTE_DIRECTORY; |
259 | 263 | } |
260 | 264 |
|
261 | 265 | bool IsFile(const std::string& path) { |
262 | | - struct stat buf; |
263 | | - if (stat(path.c_str(), &buf) != 0) |
| 266 | + DWORD attributes = GetFileAttributesForUtf8Path(path.c_str()); |
| 267 | + if (attributes == INVALID_FILE_ATTRIBUTES) { |
264 | 268 | return false; |
265 | | - return S_ISREG(buf.st_mode); |
| 269 | + } |
| 270 | + return !(attributes & |
| 271 | + (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT)); |
266 | 272 | } |
267 | 273 |
|
268 | 274 | bool UnlinkDirectory(const char* path) { |
@@ -323,7 +329,8 @@ bool TruncateFile(const fml::UniqueFD& file, size_t size) { |
323 | 329 | } |
324 | 330 |
|
325 | 331 | bool FileExists(const fml::UniqueFD& base_directory, const char* path) { |
326 | | - return IsFile(GetAbsolutePath(base_directory, path).c_str()); |
| 332 | + return GetFileAttributesForUtf8Path(base_directory, path) != |
| 333 | + INVALID_FILE_ATTRIBUTES; |
327 | 334 | } |
328 | 335 |
|
329 | 336 | bool WriteAtomically(const fml::UniqueFD& base_directory, |
|
0 commit comments