This commit is contained in:
2026-04-09 21:12:10 +02:00
parent 083c66dca7
commit 72528be2b1
3 changed files with 11 additions and 5 deletions

View File

@@ -10,7 +10,8 @@ import (
// processHardlinks creates hardlinks in destBase/destSubdir mirroring the
// structure found at contentPath (either a single file or a directory tree).
func processHardlinks(cfg *Config, contentPath, destSubdir string) error {
// torrentName is used as the subdirectory name for single-file torrents.
func processHardlinks(cfg *Config, contentPath, destSubdir, torrentName string) error {
info, err := os.Stat(contentPath)
if err != nil {
return fmt.Errorf("stat %q: %w", contentPath, err)
@@ -22,7 +23,12 @@ func processHardlinks(cfg *Config, contentPath, destSubdir string) error {
// Preserve the source directory name inside destDir
return hardlinkDir(contentPath, filepath.Join(destDir, filepath.Base(contentPath)))
}
return hardlinkFile(contentPath, filepath.Join(destDir, filepath.Base(contentPath)))
// Single-file torrent: place the file inside a subdirectory named after the torrent
subdir := torrentName
if subdir == "" {
subdir = filepath.Base(contentPath)
}
return hardlinkFile(contentPath, filepath.Join(destDir, subdir, filepath.Base(contentPath)))
}
// hardlinkDir walks srcDir and recreates the directory tree under destDir,