Documentation
¶
Overview ¶
Package hardlinktree provides utilities for creating hardlink trees that mirror torrent file layouts for cross-seeding.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create materializes the hardlink tree plan on disk. Creates necessary directories and hardlinks files from source to target paths. On failure, attempts best-effort rollback of created files.
Returns nil if all hardlinks were created successfully. Returns an error if any hardlink creation fails (after attempting rollback).
func HasCommonRootFolder ¶
func HasCommonRootFolder(files []TorrentFile) bool
HasCommonRootFolder checks if all files in the torrent share a common top-level directory. Returns true if a single root folder exists.
Examples:
- ["Movie/video.mkv", "Movie/subs.srt"] → true (common root "Movie")
- ["video.mkv", "subs.srt"] → false (files at root, no folder)
- ["Movie/video.mkv", "Other/subs.srt"] → false (different root folders)
- ["video.mkv"] → false (single file at root)
Types ¶
type ContentLayout ¶
type ContentLayout string
ContentLayout describes how qBittorrent organizes torrent content.
const ( LayoutOriginal ContentLayout = "Original" // Files placed as-is from torrent LayoutSubfolder ContentLayout = "Subfolder" // All files wrapped in a folder named after torrent LayoutNoSubfolder ContentLayout = "NoSubfolder" // Top-level folder stripped from multi-file torrent )
type ExistingFile ¶
type ExistingFile struct {
AbsPath string // Absolute path on disk
RelPath string // Relative path within the torrent structure
Size int64 // File size in bytes
}
ExistingFile represents a file that already exists on disk.
type FilePlan ¶
type FilePlan struct {
SourcePath string // Absolute path to existing file on disk
TargetPath string // Absolute path where hardlink should be created
}
FilePlan describes a single hardlink to create.
type TorrentFile ¶
type TorrentFile struct {
Path string // Relative path within the torrent (e.g., "Folder/file.mkv")
Size int64 // File size in bytes
}
TorrentFile represents a file in a torrent.
type TreePlan ¶
type TreePlan struct {
RootDir string // Root directory for the hardlink tree
Files []FilePlan // Files to hardlink
}
TreePlan describes the complete hardlink tree to create.
func BuildPlan ¶
func BuildPlan( candidateFiles []TorrentFile, existingFiles []ExistingFile, layout ContentLayout, torrentName string, destDir string, ) (*TreePlan, error)
BuildPlan creates a hardlink tree plan that maps existing files to the incoming torrent's layout.
Parameters:
- candidateFiles: Files as they appear in the INCOMING torrent (target layout)
- existingFiles: Files from the MATCHED torrent that already exist on disk
- layout: How qBittorrent will organize the torrent (from instance preferences)
- torrentName: Name of the incoming torrent (used for Subfolder layout)
- destDir: Base directory for the hardlink tree
The resulting tree will match what qBittorrent expects when adding the torrent.