Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
46552953
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
46552953
编写于
1月 30, 2020
作者:
S
stuartmorgan
提交者:
GitHub
1月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Windows file checks of unicode paths (#16105)
上级
74930e42
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
47 addition
and
11 deletion
+47
-11
fml/file_unittest.cc
fml/file_unittest.cc
+29
-0
fml/platform/win/file_win.cc
fml/platform/win/file_win.cc
+18
-11
未找到文件。
fml/file_unittest.cc
浏览文件 @
46552953
...
...
@@ -10,6 +10,7 @@
#include "flutter/fml/build_config.h"
#include "flutter/fml/file.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/unique_fd.h"
static
bool
WriteStringToFile
(
const
fml
::
UniqueFD
&
fd
,
...
...
@@ -267,3 +268,31 @@ TEST(FileTest, EmptyMappingTest) {
ASSERT_TRUE
(
fml
::
UnlinkFile
(
dir
.
fd
(),
"my_contents"
));
}
TEST
(
FileTest
,
FileTestsWork
)
{
fml
::
ScopedTemporaryDirectory
dir
;
ASSERT_TRUE
(
dir
.
fd
().
is_valid
());
const
char
*
filename
=
"some.txt"
;
auto
fd
=
fml
::
OpenFile
(
dir
.
fd
(),
filename
,
true
,
fml
::
FilePermission
::
kWrite
);
ASSERT_TRUE
(
fd
.
is_valid
());
fd
.
reset
();
ASSERT_TRUE
(
fml
::
FileExists
(
dir
.
fd
(),
filename
));
ASSERT_TRUE
(
fml
::
IsFile
(
fml
::
paths
::
JoinPaths
({
dir
.
path
(),
filename
}).
c_str
()));
ASSERT_TRUE
(
fml
::
UnlinkFile
(
dir
.
fd
(),
filename
));
}
TEST
(
FileTest
,
FileTestsSupportsUnicode
)
{
fml
::
ScopedTemporaryDirectory
dir
;
ASSERT_TRUE
(
dir
.
fd
().
is_valid
());
const
char
*
filename
=
u8"äëïöüテスト☃"
;
auto
fd
=
fml
::
OpenFile
(
dir
.
fd
(),
filename
,
true
,
fml
::
FilePermission
::
kWrite
);
ASSERT_TRUE
(
fd
.
is_valid
());
fd
.
reset
();
ASSERT_TRUE
(
fml
::
FileExists
(
dir
.
fd
(),
filename
));
ASSERT_TRUE
(
fml
::
IsFile
(
fml
::
paths
::
JoinPaths
({
dir
.
path
(),
filename
}).
c_str
()));
ASSERT_TRUE
(
fml
::
UnlinkFile
(
dir
.
fd
(),
filename
));
}
fml/platform/win/file_win.cc
浏览文件 @
46552953
...
...
@@ -8,7 +8,6 @@
#include <Shlwapi.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
#include <algorithm>
#include <sstream>
...
...
@@ -18,10 +17,6 @@
#include "flutter/fml/platform/win/errors_win.h"
#include "flutter/fml/platform/win/wstring_conversion.h"
#if defined(OS_WIN)
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#endif
namespace
fml
{
static
std
::
string
GetFullHandlePath
(
const
fml
::
UniqueFD
&
handle
)
{
...
...
@@ -80,6 +75,16 @@ static DWORD GetShareFlags(FilePermission permission) {
return
FILE_SHARE_READ
;
}
static
DWORD
GetFileAttributesForUtf8Path
(
const
char
*
absolute_path
)
{
return
::
GetFileAttributes
(
ConvertToWString
(
absolute_path
).
c_str
());
}
static
DWORD
GetFileAttributesForUtf8Path
(
const
fml
::
UniqueFD
&
base_directory
,
const
char
*
path
)
{
std
::
string
full_path
=
GetFullHandlePath
(
base_directory
)
+
"
\\
"
+
path
;
return
GetFileAttributesForUtf8Path
(
full_path
.
c_str
());
}
std
::
string
CreateTemporaryDirectory
()
{
// Get the system temporary directory.
auto
temp_dir_container
=
GetTemporaryDirectoryPath
();
...
...
@@ -253,16 +258,17 @@ bool IsDirectory(const fml::UniqueFD& directory) {
}
bool
IsDirectory
(
const
fml
::
UniqueFD
&
base_directory
,
const
char
*
path
)
{
std
::
string
full_path
=
GetFullHandlePath
(
base_directory
)
+
"
\\
"
+
path
;
return
::
GetFileAttributes
(
ConvertToWString
(
full_path
.
c_str
()).
c_str
())
&
return
GetFileAttributesForUtf8Path
(
base_directory
,
path
)
&
FILE_ATTRIBUTE_DIRECTORY
;
}
bool
IsFile
(
const
std
::
string
&
path
)
{
struct
stat
buf
;
if
(
stat
(
path
.
c_str
(),
&
buf
)
!=
0
)
DWORD
attributes
=
GetFileAttributesForUtf8Path
(
path
.
c_str
())
;
if
(
attributes
==
INVALID_FILE_ATTRIBUTES
)
{
return
false
;
return
S_ISREG
(
buf
.
st_mode
);
}
return
!
(
attributes
&
(
FILE_ATTRIBUTE_DIRECTORY
|
FILE_ATTRIBUTE_REPARSE_POINT
));
}
bool
UnlinkDirectory
(
const
char
*
path
)
{
...
...
@@ -323,7 +329,8 @@ bool TruncateFile(const fml::UniqueFD& file, size_t size) {
}
bool
FileExists
(
const
fml
::
UniqueFD
&
base_directory
,
const
char
*
path
)
{
return
IsFile
(
GetAbsolutePath
(
base_directory
,
path
).
c_str
());
return
GetFileAttributesForUtf8Path
(
base_directory
,
path
)
!=
INVALID_FILE_ATTRIBUTES
;
}
bool
WriteAtomically
(
const
fml
::
UniqueFD
&
base_directory
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录