Index: components/filesystem/directory_impl.cc |
diff --git a/components/filesystem/directory_impl.cc b/components/filesystem/directory_impl.cc |
index 58480a18a1fb70ac9faf042ceef83ccd8fb31521..e8fab2a861b4beba9838fbb6ad2a4f22bffa7968 100644 |
--- a/components/filesystem/directory_impl.cc |
+++ b/components/filesystem/directory_impl.cc |
@@ -68,25 +68,7 @@ void DirectoryImpl::OpenFile(const mojo::String& raw_path, |
return; |
} |
-#if defined(OS_WIN) |
- // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory. |
- if (base::DirectoryExists(path)) |
- open_flags |= base::File::FLAG_BACKUP_SEMANTICS; |
-#endif // OS_WIN |
- |
- base::File base_file(path, open_flags); |
- if (!base_file.IsValid()) { |
- callback.Run(GetError(base_file)); |
- return; |
- } |
- |
- base::File::Info info; |
- if (!base_file.GetInfo(&info)) { |
- callback.Run(FileError::FAILED); |
- return; |
- } |
- |
- if (info.is_directory) { |
+ if (base::DirectoryExists(path)) { |
// We must not return directories as files. In the file abstraction, we can |
// fetch raw file descriptors over mojo pipes, and passing a file |
// descriptor to a directory is a sandbox escape on Windows. |
@@ -94,6 +76,12 @@ void DirectoryImpl::OpenFile(const mojo::String& raw_path, |
return; |
} |
+ base::File base_file(path, open_flags); |
+ if (!base_file.IsValid()) { |
+ callback.Run(GetError(base_file)); |
+ return; |
+ } |
+ |
if (file.is_pending()) { |
new FileImpl(std::move(file), path, std::move(base_file), lock_table_); |
} |
@@ -110,25 +98,7 @@ void DirectoryImpl::OpenFileHandle(const mojo::String& raw_path, |
return; |
} |
-#if defined(OS_WIN) |
- // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory. |
- if (base::DirectoryExists(path)) |
- open_flags |= base::File::FLAG_BACKUP_SEMANTICS; |
-#endif // OS_WIN |
- |
- base::File base_file(path, open_flags); |
- if (!base_file.IsValid()) { |
- callback.Run(GetError(base_file), ScopedHandle()); |
- return; |
- } |
- |
- base::File::Info info; |
- if (!base_file.GetInfo(&info)) { |
- callback.Run(FileError::FAILED, ScopedHandle()); |
- return; |
- } |
- |
- if (info.is_directory) { |
+ if (base::DirectoryExists(path)) { |
// We must not return directories as files. In the file abstraction, we can |
// fetch raw file descriptors over mojo pipes, and passing a file |
// descriptor to a directory is a sandbox escape on Windows. |
@@ -136,6 +106,12 @@ void DirectoryImpl::OpenFileHandle(const mojo::String& raw_path, |
return; |
} |
+ base::File base_file(path, open_flags); |
+ if (!base_file.IsValid()) { |
+ callback.Run(GetError(base_file), ScopedHandle()); |
+ return; |
+ } |
+ |
MojoHandle mojo_handle; |
MojoResult create_result = MojoCreatePlatformHandleWrapper( |
base_file.TakePlatformFile(), &mojo_handle); |