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'); }