func (d *Directory) Create(name string, dir bool) (*Directory, *File, error) { d.Obj.Lock() defer d.Obj.Unlock() _, e := d.Res.Dir.Find(name) if e == nil { return nil, nil, syscall.EEXIST } id := uuid.NewV4().String() res := resource.NewResource(d.Repo.Repo, id) if dir { e = joinf.CreateDir(res) } else { e = joinf.CreateFile(res) } res.Dispose() if e != nil { return nil, nil, e } e = d.Res.Dir.Insert(name, id) if e != nil { d.Repo.Repo.Delete(id) return nil, nil, e } return d.load(id) }
func (r *Repository) Init() { r.Lockman.Init() r.LD = func(s string) interface{} { lr := new(LocalRes) lr.Res = resource.NewResource(r.Repo, s) f, e := joinf.LoadResource(lr.Res) if e == nil { switch v := f.(type) { case *joinf.JoinFile: lr.File = v case *joinf.Directory: lr.Dir = v } } return lr } r.F = free }