https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b879cd1661ad2fb37f603e18f6b1860c91f445ec

commit b879cd1661ad2fb37f603e18f6b1860c91f445ec
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Tue Jan 21 17:19:24 2025 +0100
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Tue Jan 21 17:31:21 2025 +0100

    Cygwin: unlink: fix error checking order
    
    Checking EPERM only makes sense if the file exists, so
    let the EEXIST check change places with the EPERM check.
    
    Add a debug statement to the EPERM condition.
    
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/syscalls.cc | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 52a5601d2c9a..1cb7821178c5 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1136,17 +1136,18 @@ unlink (const char *ourname)
       set_errno (EROFS);
       goto done;
     }
-  if (!win32_name.isondisk ())
-    {
-      set_errno (EPERM);
-      goto done;
-    }
   if (!win32_name.exists ())
     {
       debug_printf ("unlinking a nonexistent file");
       set_errno (ENOENT);
       goto done;
     }
+  if (!win32_name.isondisk ())
+    {
+      debug_printf ("unlinking a virtual file");
+      set_errno (EPERM);
+      goto done;
+    }
   else if (win32_name.isdir ())
     {
       debug_printf ("unlinking a directory");

Reply via email to