From 681e28de77a2fb40bf2f719feb6c57ad1cc0fbb9 Mon Sep 17 00:00:00 2001 From: Samanta <149822405+Shabbir7890@users.noreply.github.com> Date: Wed, 9 Sep 2026 01:44:56 +0100 Subject: [PATCH 1/2] fix(userTransfer): honour .rtorrentDisable opt-out on post-transfer restart (Refs #869) pmssUserTransferRequestRtorrentRestart() unconditionally touched the restart marker and ran the restart after a transfer, ignoring the per-user `.rtorrentDisable` opt-out that checkRtorrent honours on every cycle (GH#470). A user who had deliberately disabled rTorrent got it restarted (and their session reloaded) after any migration, until the next watchdog pass stopped it again. Skip the restart when the marker is present, matching checkRtorrent.php. --- scripts/lib/userTransfer/postSetup.php | 9 +++++++++ 1 file changed, 9 insertions(+) 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)'); From b53e814ea06015ae57740cd6849aac752fb434bd Mon Sep 17 00:00:00 2001 From: Samanta <149822405+Shabbir7890@users.noreply.github.com> Date: Sat, 26 Sep 2026 13:05:00 +0100 Subject: [PATCH 2/2] test(userTransfer): cover the .rtorrentDisable opt-out on the post-transfer restart (Refs #869) Adds the behaviour test requested on the PR: pmssUserTransferRequestRtorrentRestart() skips and logs the opt-out when ~/.rtorrentDisable is present, and requests the restart marker when it is absent. Runs under PMSS_DRY_RUN so it is hermetic (runStep logs the step without executing touch/chown), matching the existing session-rewrite tests. --- .../tests/development/userTransferTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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', [