Newer
Older
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package core
import (
"bufio"
"log"
"os"
"path/filepath"
"strings"
)
// Return a new Job that will scan path recursively for ULO/RDF files
// and pass them to the executing Importer.
func NewFileSystemJob(path string) *Job {
return &Job{
collectfunc: makeFsCollectFunc(path),
id: generateJobId(),
}
}
// Function that is called when collecting ULO/RDF from the local
// file system.
func makeFsCollectFunc(path string) func(*Job, *Collector) error {
return func(j *Job, c *Collector) error {
return filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
if err != nil {
j.Logf("error walking path=%v: %v", path, err)
return nil
}
log.Println(path)
return importLocalFile(c.im, path)
})
}
}
// Import file at path with im. Returns no error if the file at
// path is a not supported type.
func importLocalFile(im Importer, path string) error {
if strings.HasSuffix(path, ".rdf") {
return importLocalRdfFile(im, path)
}
return nil
}
// Import ULO/RDF file at path with im.
func importLocalRdfFile(im Importer, path string) error {
fd, err := os.Open(path)
if err != nil {
return err
}
defer fd.Close()
r := bufio.NewReader(fd)
return im.Import(r)
}