From 7758e98bec87e35db798f9dddc9ae5eb2a102b75 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 18 Nov 2026 13:12:10 +0530 Subject: [PATCH] fix(migration): drop the unused custom.ini backup when the write is refused disable_php_session_upload_progress backs up custom.ini before it writes the file. When site-command then refuses the write without touching the file (a hard link, a symlink swapped in, a changed file, an older site-command), the warning still said "The original custom.ini is ", as if the file had been changed, and the backup and its dir stayed after up() and down(). Only a failed write ("could not write ...") can leave the file changed, so only that case keeps the backup and names it. Any other refusal now warns "Skipped disabling session.upload_progress for : ", like the other skips, and removes the site's backup dir, and the migration's backup dir once it is empty. A backup that fails part-way is cleaned up the same way. --- ...hp_disable_php_session_upload_progress.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/migrations/container/20261021120100_site-type-php_disable_php_session_upload_progress.php b/migrations/container/20261021120100_site-type-php_disable_php_session_upload_progress.php index 0718600..5dd55e0 100644 --- a/migrations/container/20261021120100_site-type-php_disable_php_session_upload_progress.php +++ b/migrations/container/20261021120100_site-type-php_disable_php_session_upload_progress.php @@ -281,6 +281,7 @@ private function update_site( $site ) { $this->fs->touch( $backup, $stat['mtime'] ); } } catch ( \Throwable $e ) { + $this->remove_backup( $backup ); EE::warning( "Skipped disabling session.upload_progress for $site->site_url: could not back up custom.ini ({$e->getMessage()}). $manual" ); return; @@ -290,6 +291,13 @@ private function update_site( $site ) { try { self::write_custom_ini( $file, $conf_dir, $new_content, $content ); } catch ( \Exception $e ) { + // Only a failed write can leave it changed; any other refusal comes before writing. + if ( 0 !== strpos( $e->getMessage(), 'could not write' ) ) { + $this->remove_backup( $backup ); + EE::warning( "Skipped disabling session.upload_progress for $site->site_url: {$e->getMessage()}. $manual" ); + + return; + } // Kept: if putting the old content back failed too, it is the only copy. EE::warning( "Could not disable session.upload_progress for $site->site_url: {$e->getMessage()}. The original custom.ini is $backup. $manual" ); @@ -310,6 +318,24 @@ private function update_site( $site ) { EE::debug( "$site->site_url: disabled session.upload_progress in custom.ini." ); } + /** + * Remove a backup that up() didn't need, and the backup dir once it is empty. + * + * @param string $backup Saved custom.ini. + */ + private function remove_backup( string $backup ) { + + try { + $this->fs->remove( dirname( $backup ) ); + } catch ( \Throwable $e ) { + EE::debug( "Could not remove $backup: {$e->getMessage()}" ); + + return; + } + // rmdir() refuses it while it holds other sites' backups. + @rmdir( $this->backup_root ); + } + /** * Restore every file changed by up(). */