func (d *driver) Init(ctx types.Context, config gofig.Config) error { d.ctx = ctx d.config = config d.volPath = vfs.VolumesDirPath(config) d.snapPath = vfs.SnapshotsDirPath(config) ctx.WithField("vfs.root.path", vfs.RootDir(config)).Info("vfs.root") os.MkdirAll(d.volPath, 0755) os.MkdirAll(d.snapPath, 0755) d.volJSONGlobPatt = fmt.Sprintf("%s/*.json", d.volPath) d.snapJSONGlobPatt = fmt.Sprintf("%s/*.json", d.snapPath) volJSONPaths, err := d.getVolJSONs() if err != nil { return nil } d.volCount = int64(len(volJSONPaths)) - 1 snapJSONPaths, err := d.getSnapJSONs() if err != nil { return nil } d.snapCount = int64(len(snapJSONPaths)) - 1 return nil }
func (d *driver) Init(ctx types.Context, config gofig.Config) error { d.config = config d.rootDir = vfs.RootDir(config) d.devFilePath = vfs.DeviceFilePath(config) if !gotil.FileExists(d.devFilePath) { err := ioutil.WriteFile(d.devFilePath, initialDeviceFile, 0644) if err != nil { return err } } devFileLocksRWL.Lock() defer devFileLocksRWL.Unlock() devFileLocks[d.devFilePath] = &sync.RWMutex{} return nil }