only look at first 1kb of data.yaml when building tree
parent
51a8c8b425
commit
2781114863
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -92,7 +93,7 @@ func (tree Tree) getRoot(pid ID, withContent, withDeleted bool) (Branch, error)
|
|||
}
|
||||
for _, entry := range entries {
|
||||
if entry.Name() == "data.yaml" {
|
||||
if b, err := ioutil.ReadFile(path.Join(tree.root, entry.Name())); err != nil {
|
||||
if b, err := peekFile(withContent, path.Join(tree.root, entry.Name())); err != nil {
|
||||
return Branch{}, err
|
||||
} else if err := yaml.Unmarshal(b, &m.Leaf); err != nil {
|
||||
return Branch{}, err
|
||||
|
|
@ -115,6 +116,19 @@ func (tree Tree) getRoot(pid ID, withContent, withDeleted bool) (Branch, error)
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func peekFile(all bool, path string) ([]byte, error) {
|
||||
if !all {
|
||||
return ioutil.ReadFile(path)
|
||||
}
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
r := io.LimitReader(f, 1024)
|
||||
return ioutil.ReadAll(r)
|
||||
}
|
||||
|
||||
func (tree Tree) toDir(id ID) string {
|
||||
return path.Dir(tree.toData(id))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue