]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fixes for single/multi-file torrent Infos
authorMatt Joiner <anacrolix@gmail.com>
Thu, 26 Feb 2015 11:12:02 +0000 (22:12 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 26 Feb 2015 11:12:02 +0000 (22:12 +1100)
metainfo/metainfo.go

index 919ee6af2cc4094504fb7f96a8ea6d0d5dedf272..0b6056453b9d23eda9b89a5327bcb419354610cc 100644 (file)
@@ -46,6 +46,10 @@ type Info struct {
        Files       []FileInfo `bencode:"files,omitempty"`
 }
 
+func (i *Info) IsDir() bool {
+       return len(i.Files) != 0
+}
+
 // The files field, converted up from the old single-file in the parent info
 // dict if necessary. This is a helper to avoid having to conditionally handle
 // single and multi-file torrent infos.
@@ -53,7 +57,9 @@ func (i *Info) UpvertedFiles() []FileInfo {
        if len(i.Files) == 0 {
                return []FileInfo{{
                        Length: i.Length,
-                       Path:   []string{i.Name},
+                       // Callers should determine that Info.Name is the basename, and
+                       // thus a regular file.
+                       Path: nil,
                }}
        }
        return i.Files