From cecfce23a5138a0f44a9231d158c1d8541233a36 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 May 2009 10:30:33 -0400 Subject: BUG: Fix removal of read-only directories Read-only directories must be given write permission before we can remove files and subdirectories from them. --- Source/kwsys/SystemTools.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index a6512db..2d90de2 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2103,6 +2103,19 @@ bool SystemTools::RemoveFile(const char* source) bool SystemTools::RemoveADirectory(const char* source) { + // Add write permission to the directory so we can modify its + // content to remove files and directories from it. + mode_t mode; + if(SystemTools::GetPermissions(source, mode)) + { +#if defined(_WIN32) && !defined(__CYGWIN__) + mode |= S_IWRITE; +#else + mode |= S_IWUSR; +#endif + SystemTools::SetPermissions(source, mode); + } + Directory dir; dir.Load(source); size_t fileNum; -- cgit v0.12