[io-layer] When deleting a file, check for EROFS and verify if the file exists. Fixes...
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 20 Jun 2017 20:39:48 +0000 (13:39 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 20 Jun 2017 21:59:09 +0000 (14:59 -0700)
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.

mono/metadata/w32file-unix.c

index 38ca36a1a9eff4f07f8c468757c7d74c7278cb72..a9d0c7fd59b1d8eb450d87fe407a7695483b5a87 100644 (file)
@@ -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;