From 62fcacb7279abf5a17165fde5e188ac075999e95 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Tue, 19 Feb 2013 12:30:42 -0500
Subject: [PATCH] - Fixed FS#2673 - Deletion of APS instance deletes error and stats folders.

---
 server/lib/classes/aps_installer.inc.php |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/server/lib/classes/aps_installer.inc.php b/server/lib/classes/aps_installer.inc.php
index 4ac74b5..5951698 100644
--- a/server/lib/classes/aps_installer.inc.php
+++ b/server/lib/classes/aps_installer.inc.php
@@ -397,8 +397,28 @@
 
             // Now delete an existing folder (affects install and removal in the same way)
             @chdir($this->local_installpath);
-            if(file_exists($this->local_installpath)) exec("rm -Rf ".escapeshellarg($this->local_installpath).'*');
-            else mkdir($this->local_installpath, 0777, true);
+            if(file_exists($this->local_installpath)){
+				// make sure we don't delete error and stats folders
+				if($this->local_installpath == $this->document_root.'/'){
+					if(is_dir($this->document_root)){
+						$files = array_diff(scandir($this->document_root), array('.','..','error','stats'));
+						foreach($files as $file){
+							if(is_dir($this->document_root.'/'.$file)){
+								$app->file->removeDirectory($this->document_root.'/'.$file);
+							} else {
+								@unlink($this->document_root.'/'.$file);
+							}
+						}
+					} else {
+						@unlink($this->document_root);
+						mkdir($this->document_root, 0777, true);
+					}
+				} else {
+					exec("rm -Rf ".escapeshellarg($this->local_installpath).'*');
+				}
+			} else {
+				mkdir($this->local_installpath, 0777, true);
+			}
 
             if($this->handle_type == 'install')
             {            

--
Gitblit v1.9.1