-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefill.go
35 lines (30 loc) · 1019 Bytes
/
prefill.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2013, Amahi. All rights reserved.
// Use of this source code is governed by the
// license that can be found in the LICENSE file.
// Functions for prefilling cache
package metadata
import (
"os"
"path/filepath"
"time"
)
//prefill database cache using directory root, Hint, sleeptime after each read and a boolean denoting whether to prefill directory names
func (l *Library) Prefill(root string, Hint string, sleeptime time.Duration, includeDir bool) error {
filepath.Walk(root, l.getWalkFunc(Hint, sleeptime, includeDir))
return nil
}
//return function to be used on each file in the share for Tv/Movie
func (l *Library) getWalkFunc(Hint string, sleeptime time.Duration, includeDir bool) func(path string, info os.FileInfo, err error) error {
return func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if info.IsDir() != includeDir {
return nil
}
//no errors returned
l.GetMetadata(info.Name(), Hint)
time.Sleep(sleeptime)
return nil
}
}