Skip to content

Commit 9409c5e

Browse files
authored
Revert "Fix Windows file checks of unicode paths (flutter#16105)"
This reverts commit 3d5bf0b.
1 parent 3acb0c4 commit 9409c5e

File tree

2 files changed

+11
-47
lines changed

2 files changed

+11
-47
lines changed

fml/file_unittest.cc

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "flutter/fml/build_config.h"
1111
#include "flutter/fml/file.h"
1212
#include "flutter/fml/mapping.h"
13-
#include "flutter/fml/paths.h"
1413
#include "flutter/fml/unique_fd.h"
1514

1615
static bool WriteStringToFile(const fml::UniqueFD& fd,
@@ -268,31 +267,3 @@ TEST(FileTest, EmptyMappingTest) {
268267

269268
ASSERT_TRUE(fml::UnlinkFile(dir.fd(), "my_contents"));
270269
}
271-
272-
TEST(FileTest, FileTestsWork) {
273-
fml::ScopedTemporaryDirectory dir;
274-
ASSERT_TRUE(dir.fd().is_valid());
275-
const char* filename = "some.txt";
276-
auto fd =
277-
fml::OpenFile(dir.fd(), filename, true, fml::FilePermission::kWrite);
278-
ASSERT_TRUE(fd.is_valid());
279-
fd.reset();
280-
ASSERT_TRUE(fml::FileExists(dir.fd(), filename));
281-
ASSERT_TRUE(
282-
fml::IsFile(fml::paths::JoinPaths({dir.path(), filename}).c_str()));
283-
ASSERT_TRUE(fml::UnlinkFile(dir.fd(), filename));
284-
}
285-
286-
TEST(FileTest, FileTestsSupportsUnicode) {
287-
fml::ScopedTemporaryDirectory dir;
288-
ASSERT_TRUE(dir.fd().is_valid());
289-
const char* filename = u8"äëïöüテスト☃";
290-
auto fd =
291-
fml::OpenFile(dir.fd(), filename, true, fml::FilePermission::kWrite);
292-
ASSERT_TRUE(fd.is_valid());
293-
fd.reset();
294-
ASSERT_TRUE(fml::FileExists(dir.fd(), filename));
295-
ASSERT_TRUE(
296-
fml::IsFile(fml::paths::JoinPaths({dir.path(), filename}).c_str()));
297-
ASSERT_TRUE(fml::UnlinkFile(dir.fd(), filename));
298-
}

fml/platform/win/file_win.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <Shlwapi.h>
99
#include <fcntl.h>
1010
#include <limits.h>
11+
#include <sys/stat.h>
1112

1213
#include <algorithm>
1314
#include <sstream>
@@ -17,6 +18,10 @@
1718
#include "flutter/fml/platform/win/errors_win.h"
1819
#include "flutter/fml/platform/win/wstring_conversion.h"
1920

21+
#if defined(OS_WIN)
22+
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
23+
#endif
24+
2025
namespace fml {
2126

2227
static std::string GetFullHandlePath(const fml::UniqueFD& handle) {
@@ -75,16 +80,6 @@ static DWORD GetShareFlags(FilePermission permission) {
7580
return FILE_SHARE_READ;
7681
}
7782

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-
8883
std::string CreateTemporaryDirectory() {
8984
// Get the system temporary directory.
9085
auto temp_dir_container = GetTemporaryDirectoryPath();
@@ -258,17 +253,16 @@ bool IsDirectory(const fml::UniqueFD& directory) {
258253
}
259254

260255
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()) &
262258
FILE_ATTRIBUTE_DIRECTORY;
263259
}
264260

265261
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)
268264
return false;
269-
}
270-
return !(attributes &
271-
(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT));
265+
return S_ISREG(buf.st_mode);
272266
}
273267

274268
bool UnlinkDirectory(const char* path) {
@@ -329,8 +323,7 @@ bool TruncateFile(const fml::UniqueFD& file, size_t size) {
329323
}
330324

331325
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());
334327
}
335328

336329
bool WriteAtomically(const fml::UniqueFD& base_directory,

0 commit comments

Comments
 (0)