]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix info name when building from . and ..
authorMatt Joiner <anacrolix@gmail.com>
Wed, 1 Sep 2021 06:17:23 +0000 (16:17 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 2 Sep 2021 00:22:32 +0000 (10:22 +1000)
metainfo/info.go

index 1c2d0b85b9abef37b32b662fc189c504108b957d..6b251884db6984f27f820cf8306d43eb5e5dbffd 100644 (file)
@@ -26,7 +26,15 @@ type Info struct {
 // This is a helper that sets Files and Pieces from a root path and its
 // children.
 func (info *Info) BuildFromFilePath(root string) (err error) {
-       info.Name = filepath.Base(root)
+       info.Name = func() string {
+               b := filepath.Base(root)
+               switch b {
+               case ".", "..", string(filepath.Separator):
+                       return ""
+               default:
+                       return b
+               }
+       }()
        info.Files = nil
        err = filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
                if err != nil {