From df63916eb985e7750c933550894f4fcc4147a119 Mon Sep 17 00:00:00 2001 From: Jake Smith Date: Fri, 1 Dec 2023 13:44:17 +0000 Subject: [PATCH] HPCC-30955 Fix recursiveRemoveDirectory errors handling soft links Avoid unnecessarily calling setReadOnly(false) on all files, which will fail on a soft-link if the file it points to no longer exists. Signed-off-by: Jake Smith --- system/jlib/jfile.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/system/jlib/jfile.cpp b/system/jlib/jfile.cpp index 2ccc8e8b13f..dbe06675e84 100644 --- a/system/jlib/jfile.cpp +++ b/system/jlib/jfile.cpp @@ -4256,8 +4256,20 @@ void recursiveRemoveDirectory(IFile *dir) recursiveRemoveDirectory(thisFile); else { + try + { + thisFile->remove(); + continue; // i.e. continue if returns true (removed), or false (file no longer exists) + } + catch(IException *e) + { + e->Release(); + } + + // NB: not sure this is worth it. In linux the file can be read-only and still be deleted if the directory is writable + // Perhaps should ensure that the parent directory is writable, but that would require extra file ops. or interface changes thisFile->setReadOnly(false); - thisFile->remove(); + thisFile->remove(); // if gets here, the file should exist (ignore return false if doesn't), throws an exception if fails for other reason } } dir->remove();