From 2201a9b10cb4e4a9225c0962c672e2a7fa7719ec Mon Sep 17 00:00:00 2001
From: vit9696 <vit9696@users.noreply.github.com>
Date: Mon, 12 Nov 2018 14:49:35 +0300
Subject: [PATCH] Workaround dir removal on current dir on windows

---
 common/filesystem.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/common/filesystem.h b/common/filesystem.h
index ca33421..0666d4a 100644
--- a/common/filesystem.h
+++ b/common/filesystem.h
@@ -37,11 +37,15 @@ static inline bool changeDirectory(const UString & dir) {
 }
 
 static inline void removeDirectory(const UString & dir) {
-    _rmdir(dir.toLocal8Bit());
+    int r = _rmdir(dir.toLocal8Bit());
+    // Hack: unlike *nix, Windows does not permit deleting current directories.
+    if (r < 0 && errno == EACCES && changeDirectory(dir + UString("/../"))) {
+        _rmdir(dir.toLocal8Bit());
+    }
 }
 
 static inline UString getAbsPath(const UString & path) {
-    char abs[1024] = {};
+    char abs[_MAX_PATH] = {};
     if (_fullpath(abs, path.toLocal8Bit(), sizeof(abs)))
         return UString(abs);
     return path;