[PATCH v2 7/8] dir.cc: Try unlink_nt first
Ben Wijen
ben@wijen.net
Wed Jan 20 16:10:55 GMT 2021
Speedup deletion of directories.
---
winsup/cygwin/dir.cc | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index 7762557d6..470f83aee 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -22,6 +22,8 @@ details. */
#include "cygtls.h"
#include "tls_pbuf.h"
+extern NTSTATUS unlink_nt (const char *ourname, ULONG eflags);
+
extern "C" int
dirfd (DIR *dir)
{
@@ -398,6 +400,14 @@ rmdir (const char *dir)
if (msdos && p == dir + 1 && isdrive (dir))
p[1] = '\\';
}
+ if (has_dot_last_component (dir, false)) {
+ set_errno (EINVAL);
+ __leave;
+ }
+ if (NT_SUCCESS (unlink_nt (dir, FILE_DIRECTORY_FILE))) {
+ res = 0;
+ __leave;
+ }
if (!(fh = build_fh_name (dir, PC_SYM_NOFOLLOW)))
__leave; /* errno already set */;
@@ -408,8 +418,6 @@ rmdir (const char *dir)
}
else if (!fh->exists ())
set_errno (ENOENT);
- else if (has_dot_last_component (dir, false))
- set_errno (EINVAL);
else if (!fh->rmdir ())
res = 0;
delete fh;
--
2.30.0
More information about the Cygwin-patches
mailing list