From: Rodrigo Kumpera Date: Tue, 20 Jun 2017 20:39:48 +0000 (-0700) Subject: [io-layer] When deleting a file, check for EROFS and verify if the file exists. Fixes... X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=3454feb426777593f505b6732a92170a637a4383;p=mono.git [io-layer] When deleting a file, check for EROFS and verify if the file exists. Fixes #57629. Linux has this particular behavior of returning ENOFS when unlinking from an read only FS. Even if the file doesn't exists! Darwin does the sane thing and return ENOENT in this case. To workaround this, if unlink returns EROFS, we stat the file and deal with that. --- diff --git a/mono/metadata/w32file-unix.c b/mono/metadata/w32file-unix.c index 38ca36a1a9e..a9d0c7fd59b 100644 --- a/mono/metadata/w32file-unix.c +++ b/mono/metadata/w32file-unix.c @@ -2544,6 +2544,15 @@ gboolean mono_w32file_delete(const gunichar2 *name) retval = _wapi_unlink (filename); if (retval == -1) { + /* On linux, calling unlink on an non-existing file in a read-only mount will fail with EROFS. + The expected behavior is for this function to return FALSE and not trigger an exception. + To work around this behavior, we stat the file on failure. + */ + if (errno == EROFS) { + MonoIOStat stat; + if (mono_w32file_get_attributes_ex (name, &stat)) //The file exists, so must be due the RO file system + errno = EROFS; + } _wapi_set_last_path_error_from_errno (NULL, filename); } else { ret = TRUE;