Fixes #1209.
Disclosure: drafted with Claude Code at my direction; I read the cited code at the stated commit and reviewed this before posting.
Problem
Organize Files turns a 0664 audiobook file into 0600. Since the verified rename protocol became the only organize path, the coordinator creates a hidden staging file through PinnedDirectoryAnchor.CreateNewFile, which opens it with mode 0600. CopyAndVerifyAsync copies the bytes and checks the SHA-256 but never copies the source's mode, and the staging file is then published by rename, hardlink or the exclusive-create copy fallback (also 0600). The move paths already restore the mode through PinnedFileEntry.PreserveMarkerlessMetadataTo; this path did not (read at dc14be0).
Change
- Add
PinnedFileEntry.PreserveUnixModeTo, which copies the source's Unix mode onto the destination handle (no-op on Windows, and only sets it when the modes differ). - Call it in
CopyAndVerifyAsyncafter the flush and before the hash check. Both callers go through that function, so the staging file and the copy fallback target are both covered, and the hardlink fallback shares the staging inode. - The copy preserves the source's mode bits, as the move paths do (
File.SetUnixFileModeon the full mode), and adds owner read when the source is owned by another user. The staging file is owned by Listenarr and starts at 0600, so a source of 0040 or 0004 would otherwise give a copy the process can no longer reopen to verify or roll back. Those modes become 0440 and 0404; any mode that already grants owner read is unchanged (0664 stays 0664, 0640 stays 0640). The target never gets group or other permission its source lacks. Ownership is not touched. Modification time is deliberately left alone, since organize has never preserved it and that is a separate change. - Tests:
ResolveCopyUnixMode_CopyOwnedByThisProcess_GrantsOnlyOwnerReadcovers the mode rule, and `OrganizeVerifiedRename_SourceOwnedByAnotherUser_Pub...
Automated Canary build