From 87433b00ba53a8c92b0a2d80f23ad26fbfea9640 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 4 Aug 2015 00:45:15 +1000 Subject: [PATCH] Add File.DisplayPath It's used in many places, I just never formalized it. This will help prevent bugs and misuse of File.Path --- file.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/file.go b/file.go index f76b99d0..52b5bfeb 100644 --- a/file.go +++ b/file.go @@ -1,6 +1,10 @@ package torrent -import "github.com/anacrolix/torrent/metainfo" +import ( + "strings" + + "github.com/anacrolix/torrent/metainfo" +) // Provides access to regions of torrent data that correspond to its files. type File struct { @@ -28,6 +32,17 @@ func (f *File) Length() int64 { return f.length } +// The relative file path for a multi-file torrent, and the torrent name for a +// single-file torrent. +func (f *File) DisplayPath() string { + fip := f.FileInfo().Path + if len(fip) == 0 { + return f.t.Info().Name + } + return strings.Join(fip, "/") + +} + type FilePieceState struct { Bytes int64 // Bytes within the piece that are part of this File. PieceState -- 2.44.0