-
Notifications
You must be signed in to change notification settings - Fork 11
/
files.go
51 lines (41 loc) · 962 Bytes
/
files.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
)
func scrapeFiles(c chan<- *ProcessItem) {
if conf.LocalPath == "" {
return
}
log.Println("[+] Checking for local pastes.")
files, err := ioutil.ReadDir(conf.LocalPath)
if err != nil {
log.Printf("[-] Error reading %s: %s\n", conf.LocalPath, err)
return
}
// Process files in batches
batchSize := 0
switch {
case len(files) < conf.FileBatchSize:
batchSize = len(files)
default:
batchSize = conf.FileBatchSize
}
for _, file := range files[:batchSize] {
if file.IsDir() {
log.Printf("[+] Skipping directory %s\n", conf.LocalPath)
continue
}
path := filepath.Join(conf.LocalPath, file.Name())
content, err := ioutil.ReadFile(path)
if err != nil {
log.Printf("[-] Could not read file %s\n", path)
continue
}
item := &ProcessItem{Source: "Local", Location: path, Key: file.Name(), Content: string(content)}
c <- item
os.Remove(path)
}
}