pathutil

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: GPL-2.0 Imports: 3 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 HashedIsolationFolder added in v1.34.0

func HashedIsolationFolder(infohash, name string) string

HashedIsolationFolder returns <IsolationFolder>--<shortHash>, where shortHash is the first 8 characters of infohash, lowercased. It is the isolation folder for a torrent whose plain name is taken. It is also the automations template variable {{.IsolationFolderName}}.

func IsolationFolder added in v1.34.0

func IsolationFolder(name string) string

IsolationFolder returns the name of the isolation folder for a torrent: the sanitized torrent name, cut at a full character to fit 255 bytes with room for the hash of HashedIsolationFolder.

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