Skip to content

Commit

Permalink
Fix file flags for directories and backslashes on Windows. (flutter#5387
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chinmaygarde authored May 25, 2018
1 parent b537231 commit 37f456c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions fml/platform/win/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

#include <Shlwapi.h>

#include <algorithm>
#include <sstream>

#include "flutter/fml/platform/win/wstring_conversion.h"

namespace fml {

fml::UniqueFD OpenFile(const std::wstring& path,
OpenPermission permission,
bool is_directory) {
static fml::UniqueFD OpenFile(std::wstring path,
OpenPermission permission,
bool is_directory) {
if (path.size() == 0) {
return fml::UniqueFD{};
}
Expand All @@ -36,15 +37,22 @@ fml::UniqueFD OpenFile(const std::wstring& path,
break;
}

return fml::UniqueFD{::CreateFile(
path.c_str(), // lpFileName
desired_access, // dwDesiredAccess
FILE_SHARE_READ, // dwShareMode
0, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
0 // hTemplateFile
)};
DWORD flags = FILE_ATTRIBUTE_NORMAL;

if (is_directory) {
flags |= FILE_FLAG_BACKUP_SEMANTICS;
}

std::replace(path.begin(), path.end(), '/', '\\');

return fml::UniqueFD{::CreateFile(path.c_str(), // lpFileName
desired_access, // dwDesiredAccess
FILE_SHARE_READ, // dwShareMode
0, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
flags, // dwFlagsAndAttributes
0 // hTemplateFile
)};
}

fml::UniqueFD OpenFile(const char* path,
Expand Down

0 comments on commit 37f456c

Please sign in to comment.