8 "github.com/anacrolix/torrent/metainfo"
11 // Determines the filepath to be used for each file in a torrent.
12 type FilePathMaker func(opts FilePathMakerOpts) string
14 // Determines the directory for a given torrent within a storage client.
15 type TorrentDirFilePathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string
17 // Info passed to a FilePathMaker.
18 type FilePathMakerOpts struct {
20 File *metainfo.FileInfo
23 // defaultPathMaker just returns the storage client's base directory.
24 func defaultPathMaker(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string {
28 func infoHashPathMaker(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string {
29 return filepath.Join(baseDir, infoHash.HexString())
32 func isSubFilepath(base, sub string) bool {
33 rel, err := filepath.Rel(base, sub)
37 return rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator))