Not having to query file information improves unlink speed. --- winsup/cygwin/syscalls.cc | 68 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 79e4a4422..8aecdf453 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1305,6 +1305,18 @@ _unlink_ntpc_ (path_conv& pc, bool shareable) return status; } +NTSTATUS +unlink_nt (const char *ourname, ULONG eflags) +{ + path_conv pc (ourname, PC_SYM_NOFOLLOW | PC_FS_USE_PREFIX_HASH | PC_SKIP_SYM_CHECK, NULL); + dev_t devn = pc.get_device (); + if (pc.error || isproc_dev (devn)) + return STATUS_CANNOT_DELETE; + + PUNICODE_STRING ntpath = pc.get_nt_native_path (); + return _unlink_nt (ntpath, eflags, 0); +} + NTSTATUS unlink_ntpc (path_conv &pc) { @@ -1322,37 +1334,41 @@ unlink (const char *ourname) { int res = -1; dev_t devn; - NTSTATUS status; + NTSTATUS status = unlink_nt (ourname, FILE_NON_DIRECTORY_FILE); - path_conv win32_name (ourname, PC_SYM_NOFOLLOW, stat_suffixes); + if (!NT_SUCCESS (status)) + { + path_conv win32_name (ourname, PC_SYM_NOFOLLOW, stat_suffixes); - if (win32_name.error) - { - set_errno (win32_name.error); - goto done; - } + if (win32_name.error) + { + set_errno (win32_name.error); + goto done; + } - devn = win32_name.get_device (); - if (isproc_dev (devn)) - { - set_errno (EROFS); - goto done; - } + devn = win32_name.get_device (); + if (isproc_dev (devn)) + { + set_errno (EROFS); + goto done; + } - if (!win32_name.exists ()) - { - debug_printf ("unlinking a nonexistent file"); - set_errno (ENOENT); - goto done; - } - else if (win32_name.isdir ()) - { - debug_printf ("unlinking a directory"); - set_errno (EISDIR); - goto done; - } + if (!win32_name.exists ()) + { + debug_printf ("unlinking a nonexistent file"); + set_errno (ENOENT); + goto done; + } + else if (win32_name.isdir ()) + { + debug_printf ("unlinking a directory"); + set_errno (EISDIR); + goto done; + } + + status = unlink_ntpc (win32_name); + } - status = unlink_ntpc (win32_name); if (NT_SUCCESS (status)) res = 0; else -- 2.29.2