FileNotFoundException on Mono on Windows and on .NET when target doesn't exist
FileInfoTest.MoveTo_DestFileName_DirectoryDoesNotExist() expects
FileNotFoundException to be thrown but on Windows a DirectoryNotFoundException
is thrown instead.
This patch changes MoveFile() in mono/io-layer/io.c to set the last error to
ERROR_PATH_NOT_FOUND rather than ERROR_FILE_NOT_FOUND when the destination
path doesn't exist. This results in a DirectoryNotFoundException being thrown
in managed code rather than FileNotFoundException. This is the behaviour
observed in .NET.
Also updated FileInfoTest.MoveTo_DestFileName_DirectoryDoesNotExist() to check
for DirectoryNotFoundException rather than FileNotFoundException.
try {
info.MoveTo (destFile);
Assert.Fail ("#1");
- } catch (FileNotFoundException ex) {
+ } catch (DirectoryNotFoundException ex) {
// Could not find a part of the path
- Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
+ Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
case EXDEV:
/* Ignore here, it is dealt with below */
break;
-
+
+ case ENOENT:
+ /* We already know src exists. Must be dest that doesn't exist. */
+ _wapi_set_last_path_error_from_errno (NULL, utf8_dest_name);
+ break;
+
default:
- _wapi_set_last_path_error_from_errno (NULL, utf8_name);
+ _wapi_set_last_error_from_errno ();
}
}