Skip to content

Commit

Permalink
Cygwin: unlink: fix error checking order
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
github-cygwin committed Jan 21, 2025
1 parent 890086a commit b879cd1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions winsup/cygwin/syscalls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b879cd1

Please sign in to comment.