1010
1111namespace Joomla \CMS \Installation \Model ;
1212
13+ use Joomla \Filesystem \Exception \FilesystemException ;
1314use Joomla \Filesystem \File ;
1415use Joomla \Filesystem \Folder ;
1516
@@ -33,15 +34,48 @@ class CleanupModel extends BaseInstallationModel
3334 */
3435 public function deleteInstallationFolder ()
3536 {
36- $ return = Folder::delete (JPATH_INSTALLATION ) && (!file_exists (JPATH_ROOT . '/joomla.xml ' ) || File::delete (JPATH_ROOT . '/joomla.xml ' ));
37+ // First, we try to delete the installation folder
38+ try {
39+ Folder::delete (JPATH_INSTALLATION );
40+ } catch (FilesystemException $ e ) {
41+ /**
42+ * Windows quirk: The installation folder may fail to delete because
43+ * index.php, though already deleted, remains locked by PHP until
44+ * the request ends. If no subfolders and only that file is present,
45+ * we can assume the deletion effectively successful and continue cleanup.
46+ */
47+ if (PHP_OS_FAMILY === 'Windows ' ) {
48+ $ files = Folder::files (JPATH_INSTALLATION );
49+ $ folders = Folder::folders (JPATH_INSTALLATION );
50+
51+ if (\count ($ folders ) > 0 || \count ($ files ) > 1 ) {
52+ return false ;
53+ }
54+ } else {
55+ return false ;
56+ }
57+ }
58+
59+ // Remove file joomla.xml in root folder if it exists
60+ if (file_exists (JPATH_ROOT . '/joomla.xml ' )) {
61+ try {
62+ File::delete (JPATH_ROOT . '/joomla.xml ' );
63+ } catch (FilesystemException $ e ) {
64+ return false ;
65+ }
66+ }
3767
3868 // Rename the robots.txt.dist file if robots.txt doesn't exist
39- if ($ return && !file_exists (JPATH_ROOT . '/robots.txt ' ) && file_exists (JPATH_ROOT . '/robots.txt.dist ' )) {
40- $ return = File::move (JPATH_ROOT . '/robots.txt.dist ' , JPATH_ROOT . '/robots.txt ' );
69+ if (!file_exists (JPATH_ROOT . '/robots.txt ' ) && file_exists (JPATH_ROOT . '/robots.txt.dist ' )) {
70+ try {
71+ File::move (JPATH_ROOT . '/robots.txt.dist ' , JPATH_ROOT . '/robots.txt ' );
72+ } catch (FilesystemException $ e ) {
73+ return false ;
74+ }
4175 }
4276
4377 clearstatcache (true , JPATH_INSTALLATION . '/index.php ' );
4478
45- return $ return ;
79+ return true ;
4680 }
4781}
0 commit comments