Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions scripts/lib/tests/development/userTransferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
9 changes: 9 additions & 0 deletions scripts/lib/userTransfer/postSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand Down
Loading