From 20225e7b238c13c99ed71510089d103c6da84142 Mon Sep 17 00:00:00 2001
From: Webslice <webslice@bixels.nl>
Date: Thu, 12 Dec 2019 09:02:15 +0100
Subject: [PATCH] Prevent conflicting APS install paths

---
 interface/lib/classes/aps_guicontroller.inc.php | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/interface/lib/classes/aps_guicontroller.inc.php b/interface/lib/classes/aps_guicontroller.inc.php
index 8a764a9c5c..8e4c17af79 100644
--- a/interface/lib/classes/aps_guicontroller.inc.php
+++ b/interface/lib/classes/aps_guicontroller.inc.php
@@ -637,11 +637,27 @@ class ApsGUIController extends ApsBase
 						// The location might be empty but the DB return must not be false!
 						if($location_for_domain) $used_path .= $location_for_domain['value'];
 
+						// If user is trying to install into exactly the same path, give an error
 						if($new_path == $used_path)
 						{
 							$temp_errstr = $app->lng('error_used_location');
 							break;
 						}
+
+						// If the new path is _below_ an existing path, give an error because the
+						// installation will delete the files of the existing APS installation
+						if (mb_substr($used_path, 0, mb_strlen($new_path)) === $new_path) {
+							$temp_errstr = $app->lng('error_used_location');
+							break;
+						}
+
+						// If the new path is _within_ an existing path, give an error. Even if
+						// installation would proceed fine in theory, deleting the "lower" package
+						// in the future would also inadvertedly delete the "nested" package
+						if (mb_substr($new_path, 0, mb_strlen($used_path)) === $used_path) {
+							$temp_errstr = $app->lng('error_used_location');
+							break;
+						}
 					}
 				}
 			}
-- 
GitLab