MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Init

Method Init

internal/caches/list_file_sqlite.go:50–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50func (this *SQLiteFileList) Init() error {
51 // 检查目录是否存在
52 _, err := os.Stat(this.dir)
53 if err != nil {
54 err = os.MkdirAll(this.dir, 0777)
55 if err != nil {
56 return err
57 }
58 remotelogs.Println("CACHE", "create cache dir '"+this.dir+"'")
59 }
60
61 var dir = this.dir
62 if dir == "/" {
63 // 防止sqlite提示authority错误
64 dir = ""
65 }
66
67 remotelogs.Println("CACHE", "loading database from '"+dir+"' ...")
68 var wg = &sync.WaitGroup{}
69 var locker = sync.Mutex{}
70 var lastErr error
71
72 for i := 0; i < CountFileDB; i++ {
73 wg.Add(1)
74 go func(i int) {
75 defer wg.Done()
76
77 var db = NewSQLiteFileListDB()
78 dbErr := db.Open(dir + "/db-" + types.String(i) + ".db")
79 if dbErr != nil {
80 lastErr = dbErr
81 return
82 }
83
84 dbErr = db.Init()
85 if dbErr != nil {
86 lastErr = dbErr
87 return
88 }
89
90 locker.Lock()
91 this.dbList[i] = db
92 locker.Unlock()
93 }(i)
94 }
95 wg.Wait()
96
97 if lastErr != nil {
98 return lastErr
99 }
100
101 // 升级老版本数据库
102 goman.New(func() {
103 this.upgradeOldDB()
104 })
105
106 return nil
107}

Callers

nothing calls this directly

Calls 13

upgradeOldDBMethod · 0.95
PrintlnFunction · 0.92
NewFunction · 0.92
NewSQLiteFileListDBFunction · 0.85
DoneMethod · 0.80
StatMethod · 0.65
AddMethod · 0.65
InitMethod · 0.65
OpenMethod · 0.45
StringMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected