Init 初始化
()
| 231 | |
| 232 | // Init 初始化 |
| 233 | func (this *FileStorage) Init() error { |
| 234 | this.locker.Lock() |
| 235 | defer this.locker.Unlock() |
| 236 | |
| 237 | var before = time.Now() |
| 238 | |
| 239 | // 配置 |
| 240 | var options = serverconfigs.NewHTTPFileCacheStorage() |
| 241 | optionsJSON, err := json.Marshal(this.policy.Options) |
| 242 | if err != nil { |
| 243 | return err |
| 244 | } |
| 245 | err = json.Unmarshal(optionsJSON, options) |
| 246 | if err != nil { |
| 247 | return err |
| 248 | } |
| 249 | this.options = options |
| 250 | |
| 251 | if !filepath.IsAbs(this.options.Dir) { |
| 252 | this.options.Dir = Tea.Root + Tea.DS + this.options.Dir |
| 253 | } |
| 254 | |
| 255 | this.options.Dir = filepath.Clean(this.options.Dir) |
| 256 | var dir = this.options.Dir |
| 257 | |
| 258 | var subDirs = []*FileDir{} |
| 259 | for _, subDir := range this.options.SubDirs { |
| 260 | subDirs = append(subDirs, &FileDir{ |
| 261 | Path: subDir.Path, |
| 262 | Capacity: subDir.Capacity, |
| 263 | IsFull: false, |
| 264 | }) |
| 265 | } |
| 266 | this.subDirs = subDirs |
| 267 | if len(subDirs) > 0 { |
| 268 | this.checkDiskSpace() |
| 269 | } |
| 270 | |
| 271 | if len(dir) == 0 { |
| 272 | return errors.New("[CACHE]cache storage dir can not be empty") |
| 273 | } |
| 274 | |
| 275 | // read list |
| 276 | var list ListInterface |
| 277 | var sqliteIndexesDir = dir + "/p" + types.String(this.policy.Id) + "/.indexes" |
| 278 | _, sqliteIndexesDirErr := os.Stat(sqliteIndexesDir) |
| 279 | if sqliteIndexesDirErr == nil || !teaconst.EnableKVCacheStore { |
| 280 | list = NewSQLiteFileList(sqliteIndexesDir) |
| 281 | err = list.Init() |
| 282 | if err != nil { |
| 283 | return err |
| 284 | } |
| 285 | list.(*SQLiteFileList).SetOldDir(dir + "/p" + types.String(this.policy.Id)) |
| 286 | } else { |
| 287 | list = NewKVFileList(dir + "/p" + types.String(this.policy.Id) + "/.stores") |
| 288 | err = list.Init() |
| 289 | if err != nil { |
| 290 | return err |
nothing calls this directly
no test coverage detected