-
Notifications
You must be signed in to change notification settings - Fork 9
/
init_store_path.go
45 lines (40 loc) · 1.3 KB
/
init_store_path.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
package cmd
import (
"os"
"path"
"github.com/yumenaka/comi/config"
"github.com/yumenaka/comi/util/logger"
)
// initStorePath 添加默认扫描路径
func initStorePath(args []string) {
wd, err := os.Getwd()
if err != nil {
logger.Infof("Failed to get working directory:%s", err)
}
logger.Infof("Working directory:%s", wd)
//没指定路径或文件,同时也配置文件也没设定书库文件夹
if len(args) == 0 && len(config.Config.LocalStores) == 0 {
config.Config.LocalStores = append(config.Config.LocalStores, wd)
}
//指定了多个路径,就都扫描一遍
for _, arg := range args {
config.Config.LocalStores = append(config.Config.LocalStores, arg)
}
//启用上传,则添加upload目录
if config.Config.EnableUpload {
if config.Config.UploadPath != "" {
config.Config.LocalStores = append(config.Config.LocalStores, config.Config.UploadPath)
}
if config.Config.UploadPath == "" && len(config.Config.LocalStores) > 0 {
createUploadFolder := true
for _, checkPath := range config.Config.LocalStores {
if checkPath == path.Join(config.Config.LocalStores[0], "upload") {
createUploadFolder = false
}
}
if createUploadFolder {
config.Config.LocalStores = append(config.Config.LocalStores, path.Join(config.Config.LocalStores[0], "upload"))
}
}
}
}