Commit 1c22fdc3 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[NativeFS] Return correct error when trying to create a file/directory.

Make sure this actually fails on posix, and return the correct error
code when trying to create a file or directory fails because the other
type already exists.

Bug: 1098001
Change-Id: I265c079a436e2107e1ee9c146e87c9e9ea3db7a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317989
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791450}
parent f8bfcc4b
...@@ -147,6 +147,10 @@ base::File::Error NativeFileUtil::EnsureFileExists(const base::FilePath& path, ...@@ -147,6 +147,10 @@ base::File::Error NativeFileUtil::EnsureFileExists(const base::FilePath& path,
// If its parent does not exist, should return NOT_FOUND error. // If its parent does not exist, should return NOT_FOUND error.
return base::File::FILE_ERROR_NOT_FOUND; return base::File::FILE_ERROR_NOT_FOUND;
// If |path| is a directory, return an error.
if (base::DirectoryExists(path))
return base::File::FILE_ERROR_NOT_A_FILE;
// Tries to create the |path| exclusively. This should fail // Tries to create the |path| exclusively. This should fail
// with base::File::FILE_ERROR_EXISTS if the path already exists. // with base::File::FILE_ERROR_EXISTS if the path already exists.
base::File file(path, base::File::FLAG_CREATE | base::File::FLAG_READ); base::File file(path, base::File::FLAG_CREATE | base::File::FLAG_READ);
...@@ -180,7 +184,7 @@ base::File::Error NativeFileUtil::CreateDirectory(const base::FilePath& path, ...@@ -180,7 +184,7 @@ base::File::Error NativeFileUtil::CreateDirectory(const base::FilePath& path,
// If file exists at the path. // If file exists at the path.
if (path_exists && !base::DirectoryExists(path)) if (path_exists && !base::DirectoryExists(path))
return base::File::FILE_ERROR_EXISTS; return base::File::FILE_ERROR_NOT_A_DIRECTORY;
if (!base::CreateDirectory(path)) if (!base::CreateDirectory(path))
return base::File::FILE_ERROR_FAILED; return base::File::FILE_ERROR_FAILED;
......
This is a testharness.js-based test.
PASS User succesfully selected an empty directory.
PASS User granted write access.
PASS getDirectoryHandle(create=false) rejects for non-existing directories
PASS getDirectoryHandle(create=true) creates an empty directory
PASS getDirectoryHandle(create=false) returns existing directories
PASS getDirectoryHandle(create=true) returns existing directories without erasing
FAIL getDirectoryHandle() when a file already exists with the same name promise_rejects_dom: function "function() { throw e }" threw object "InvalidModificationError: An attempt was made to create a file or directory where an element already exists." that is not a DOMException TypeMismatchError: property "code" is equal to 13, expected 17
PASS getDirectoryHandle() with empty name
PASS getDirectoryHandle() with "." name
PASS getDirectoryHandle() with ".." name
PASS getDirectoryHandle(create=false) with a path separator when the directory exists
PASS getDirectoryHandle(create=true) with a path separator
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS User succesfully selected an empty directory.
PASS User granted write access.
PASS getFileHandle(create=false) rejects for non-existing files
PASS getFileHandle(create=true) creates an empty file for non-existing files
PASS getFileHandle(create=false) returns existing files
PASS getFileHandle(create=true) returns existing files without erasing
PASS getFileHandle(create=false) when a directory already exists with the same name
FAIL getFileHandle(create=true) when a directory already exists with the same name assert_unreached: Should have rejected: undefined Reached unreachable code
PASS getFileHandle() with empty name
PASS getFileHandle() with "." name
PASS getFileHandle() with ".." name
PASS getFileHandle(create=false) with a path separator when the file exists.
PASS getFileHandle(create=true) with a path separator
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS User succesfully selected an empty directory.
PASS User granted write access.
PASS getFileHandle(create=false) rejects for non-existing files
PASS getFileHandle(create=true) creates an empty file for non-existing files
PASS getFileHandle(create=false) returns existing files
PASS getFileHandle(create=true) returns existing files without erasing
PASS getFileHandle(create=false) when a directory already exists with the same name
FAIL getFileHandle(create=true) when a directory already exists with the same name assert_unreached: Should have rejected: undefined Reached unreachable code
PASS getFileHandle() with empty name
PASS getFileHandle() with "." name
PASS getFileHandle() with ".." name
PASS getFileHandle(create=false) with a path separator when the file exists.
PASS getFileHandle(create=true) with a path separator
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS User succesfully selected an empty directory.
PASS User granted write access.
PASS getFileHandle(create=false) rejects for non-existing files
PASS getFileHandle(create=true) creates an empty file for non-existing files
PASS getFileHandle(create=false) returns existing files
PASS getFileHandle(create=true) returns existing files without erasing
PASS getFileHandle(create=false) when a directory already exists with the same name
FAIL getFileHandle(create=true) when a directory already exists with the same name promise_rejects_dom: function "function() { throw e }" threw object "NoModificationAllowedError: An attempt was made to write to a file or directory which could not be modified due to the state of the underlying filesystem." that is not a DOMException TypeMismatchError: property "code" is equal to 7, expected 17
PASS getFileHandle() with empty name
PASS getFileHandle() with "." name
PASS getFileHandle() with ".." name
PASS getFileHandle(create=false) with a path separator when the file exists.
PASS getFileHandle(create=true) with a path separator
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment