pathutil

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: GPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pathutil provides cross-platform path sanitization utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsolationFolderName

func IsolationFolderName(infohash, name string) string

IsolationFolderName generates a human-readable isolation folder name for hardlink cross-seeding. Format: <sanitized-name>--<shortHash>

This is used when torrents need isolation (e.g., rootless torrents with Original layout, or NoSubfolder layout) to prevent file conflicts while keeping the folder name readable and unique.

Example: "My.Movie.2024.1080p.BluRay--abcdef12"

func SanitizePathSegment

func SanitizePathSegment(name string) string

SanitizePathSegment sanitizes a path segment (directory or file name) to be safe for use across platforms (Unix, Windows, macOS).

It performs the following transformations:

  • Removes characters illegal in Windows: < > : " / \ | ? *
  • Removes ASCII control characters (0x00-0x1F)
  • Removes trailing dots and spaces (Windows restriction)
  • Prefixes Windows reserved names (CON, PRN, etc.) with underscore
  • Returns "_" if the result would be empty

func TorrentPathComponent added in v1.24.0

func TorrentPathComponent(component string) string

TorrentPathComponent maps one component of a torrent's file path to the name libtorrent, and therefore qBittorrent, puts on disk for it.

libtorrent's sanitize_append_path_element replaces an empty component with "_" instead of dropping it, on every release line qBittorrent ships (1.1, 1.2, 2.0). Go's path.Join drops it, which would place a link tree one directory above where qBittorrent looks for the data. Only this rule is mirrored: libtorrent's handling of "." and ".." differs between 1.x and 2.0, so copying it would produce wrong paths for whichever version we did not target.

Types

This section is empty.

Jump to

Keyboard shortcuts

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