diff --git a/scripts/lib/tests/development/userTransferTest.php b/scripts/lib/tests/development/userTransferTest.php index a267f65a9..2f87ab091 100644 --- a/scripts/lib/tests/development/userTransferTest.php +++ b/scripts/lib/tests/development/userTransferTest.php @@ -430,6 +430,35 @@ public function testRewriteRtorrentSessionPathsReportsWhenNothingNeedsRewrite(): $this->assertStringContainsString('[INFO] rTorrent session rewrite found no /home path references to update', $output); } + public function testRequestRtorrentRestartSkipsWhenUserOptedOut(): void + { + $home = $this->pmssMakeUserWebHome('pmss-userTransfer-rtorrent-optout-', 'newuser'); + $this->pmssWriteFile($home.'/.rtorrentDisable', ''); + $logDir = $this->pmssEnsureDir($this->pmssMakeTempDir('pmss-userTransfer-optout-logs-')); + + list(, $output) = $this->pmssCaptureStdout(function () use ($home): void { + \pmssUserTransferRequestRtorrentRestart($home, 'newuser'); + }, ['PMSS_DRY_RUN' => '1', 'PMSS_LOG_DIR' => $logDir]); + + // The opt-out is honoured: the skip is logged and no restart marker is requested. + $this->assertStringContainsString('[INFO] Skipping rTorrent restart: user opted out via .rtorrentDisable', $output); + $this->assertStringNotContainsString('Requesting rTorrent restart marker', $output); + } + + public function testRequestRtorrentRestartRequestsMarkerWithoutOptOut(): void + { + $home = $this->pmssMakeUserWebHome('pmss-userTransfer-rtorrent-restart-', 'newuser'); + $logDir = $this->pmssEnsureDir($this->pmssMakeTempDir('pmss-userTransfer-restart-logs-')); + + list(, $output) = $this->pmssCaptureStdout(function () use ($home): void { + \pmssUserTransferRequestRtorrentRestart($home, 'newuser'); + }, ['PMSS_DRY_RUN' => '1', 'PMSS_LOG_DIR' => $logDir]); + + // Control: without the marker the restart is requested as before. + $this->assertStringContainsString('Requesting rTorrent restart marker', $output); + $this->assertStringNotContainsString('user opted out via .rtorrentDisable', $output); + } + public function testRtorrentRestartScriptUsesLiveUserProcessFallback(): void { $this->pmssAssertRepoFileContainsAllStrings('etc/skel/.rtorrentRestart.php', [ diff --git a/scripts/lib/userTransfer/postSetup.php b/scripts/lib/userTransfer/postSetup.php index 191e97160..6caff9ba4 100644 --- a/scripts/lib/userTransfer/postSetup.php +++ b/scripts/lib/userTransfer/postSetup.php @@ -67,6 +67,15 @@ function pmssUserTransferRenameRutorrentShare(string $home, string $remoteUser, function pmssUserTransferRequestRtorrentRestart(string $home, string $localUser): void { + // Respect the per-user rTorrent opt-out (GH#470, GH#869): `.rtorrentDisable` + // means "stop and stay stopped". checkRtorrent honours it on every cron + // cycle, so restarting here would only be undone within a few minutes while + // needlessly reloading the migrated session against the user's wishes. Skip. + if (is_file(rtrim($home, '/').'/.rtorrentDisable')) { + logMessage('[INFO] Skipping rTorrent restart: user opted out via .rtorrentDisable'); + return; + } + $wwwDir = $home.'/www'; if (!is_dir($wwwDir) || is_link($wwwDir) || !pmssUserTransferIsPathWithinHome($wwwDir, $home)) { logMessage('[WARN] Skipping rTorrent restart marker (www dir missing or unsafe)');