hardlink

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: 6 Imported by: 0

Documentation

Overview

Package hardlink provides filesystem hardlink detection utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAnyHardlinked

func IsAnyHardlinked(basePath string, filePaths []string) bool

IsAnyHardlinked returns true if at least one REGULAR file has link count > 1. Directories, symlinks, and non-regular files are skipped. Inaccessible files are skipped. Handles both relative paths (joined with basePath) and absolute paths.

func LinkInfo

func LinkInfo(fi os.FileInfo, _ string) (fileID string, nlink uint64, err error)

LinkInfo returns the unique file identifier and link count for a file. On Unix systems, fileID is composed of device ID and inode number. This enables hardlink accounting to distinguish between: - hardlinks within the torrent set (cross-seeds) - hardlinks outside the torrent set (arr imports)

Types

type FileID added in v1.13.0

type FileID struct {
	Dev uint64
	Ino uint64
}

FileID uniquely identifies a physical file on disk. On Unix, this is the (device, inode) pair. This type is comparable and can be used as a map key without allocations.

func GetFileID added in v1.13.0

func GetFileID(fi os.FileInfo, _ string) (FileID, uint64, error)

GetFileID returns the FileID and link count for a file without allocations. This is more efficient than LinkInfo when you don't need the string representation.

func (FileID) Bytes added in v1.13.0

func (f FileID) Bytes() []byte

Bytes returns a byte slice representation of the FileID for hashing. This is used for computing file signatures across platforms.

func (FileID) IsZero added in v1.13.0

func (f FileID) IsZero() bool

IsZero returns true if the FileID is the zero value (uninitialized).

func (FileID) Less added in v1.13.0

func (f FileID) Less(other FileID) bool

Less returns true if this FileID is less than other. Used for sorting FileIDs.

func (FileID) WriteToHash added in v1.13.0

func (f FileID) WriteToHash(h hash.Hash)

WriteToHash writes the FileID bytes directly to a hash.Hash. Uses a stack-allocated buffer to avoid heap escapes (unlike Bytes which returns a slice).

Jump to

Keyboard shortcuts

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