From 085e978ce43da9ce016586f5116fe344a661b019 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Mon, 7 Feb 2022 23:15:56 +0000 Subject: [PATCH] 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 Commit-Queue: Brian Quinlan --- runtime/bin/directory_win.cc | 1 + tests/standalone/io/directory_rename_test.dart | 5 ++++- tests/standalone_2/io/directory_rename_test.dart | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc index 3e1992397b4..41d58e83513 100644 --- a/runtime/bin/directory_win.cc +++ b/runtime/bin/directory_win.cc @@ -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); diff --git a/tests/standalone/io/directory_rename_test.dart b/tests/standalone/io/directory_rename_test.dart index de14cea0b8a..277b5ba697e 100644 --- a/tests/standalone/io/directory_rename_test.dart +++ b/tests/standalone/io/directory_rename_test.dart @@ -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'); } diff --git a/tests/standalone_2/io/directory_rename_test.dart b/tests/standalone_2/io/directory_rename_test.dart index 5f47913813c..18cbba31d20 100644 --- a/tests/standalone_2/io/directory_rename_test.dart +++ b/tests/standalone_2/io/directory_rename_test.dart @@ -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'); }