hardlinktree

package
v1.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: GPL-2.0 Imports: 7 Imported by: 0

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

func Create(plan *TreePlan) error

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)

func Rollback

func Rollback(plan *TreePlan) error

Rollback removes created files and directories from a failed plan execution. Best-effort: continues even if some removals fail.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL