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