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(). */