Fix on Windows, renaming a file using the Directory class generates an incorrect exception

TEST=unit
Bug: https://github.com/dart-lang/sdk/issues/47713
Change-Id: I603a452cece478ad5ddd85d47e9cfe02cee3f4d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231801
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Brian Quinlan 2022-02-07 23:15:56 +00:00 committed by Commit Bot
parent 867e155ff6
commit 085e978ce4
3 changed files with 9 additions and 2 deletions

View file

@ -508,6 +508,7 @@ bool Directory::Rename(Namespace* namespc,
Utf8ToWideScope system_path(prefixed_dir);
ExistsResult exists = ExistsHelper(system_path.wide());
if (exists != EXISTS) {
SetLastError(ERROR_FILE_NOT_FOUND);
return false;
}
const char* prefixed_new_dir = PrefixLongDirectoryPath(new_path);

View file

@ -141,7 +141,10 @@ testRenameButActuallyFile() async {
} on FileSystemException catch (e) {
Expect.isTrue(
e.message.contains('Rename failed'), 'Unexpected error: $e');
if (Platform.isLinux || Platform.isMacOS) {
if (Platform.isWindows) {
Expect.isTrue(e.osError!.message.contains('cannot find the file'),
'Unexpected error: $e');
} else if (Platform.isLinux || Platform.isMacOS) {
Expect.isTrue(e.osError!.message.contains('Not a directory'),
'Unexpected error: $e');
}

View file

@ -143,7 +143,10 @@ testRenameButActuallyFile() async {
} on FileSystemException catch (e) {
Expect.isTrue(
e.message.contains('Rename failed'), 'Unexpected error: $e');
if (Platform.isLinux || Platform.isMacOS) {
if (Platform.isWindows) {
Expect.isTrue(e.osError.message.contains('cannot find the file'),
'Unexpected error: $e');
} else if (Platform.isLinux || Platform.isMacOS) {
Expect.isTrue(e.osError.message.contains('Not a directory'),
'Unexpected error: $e');
}