Example #1
0
func (d *Directory) Delete(name string, dir bool) error {
	d.Obj.Lock()
	defer d.Obj.Unlock()
	{
		id, e := d.Res.Dir.Find(name)
		if e != nil {
			return e
		}
		fm, e := joinf.LoadMetaDirect(d.Repo.Repo, id)
		if e != nil {
			return e
		}
		if fm.IsDir && !dir {
			return syscall.ENOTDIR
		} else if dir && !fm.IsDir {
			return syscall.EISDIR
		}
	}
	id, e := d.Res.Dir.Delete(name)
	if e != nil {
		return e
	}
	obj := d.Repo.Load(id)
	lr := obj.Obj.(*LocalRes)
	lr.Res.Delete()
	obj.Decr()
	return nil
}
Example #2
0
func (d *Directory) IsEmpty() bool {
	d.Obj.Lock()
	defer d.Obj.Unlock()
	r := d.Res.Dir.ListUp()
	for _, p := range r {
		_, e := joinf.LoadMetaDirect(d.Repo.Repo, p[1])
		if e != nil {
			continue
		}
		return false
	}
	return true
}
Example #3
0
func (d *Directory) Listup() []Entry {
	d.Obj.Lock()
	defer d.Obj.Unlock()
	r := d.Res.Dir.ListUp()
	el := make([]Entry, 0, len(r))
	for _, p := range r {
		fm, e := joinf.LoadMetaDirect(d.Repo.Repo, p[1])
		if e != nil {
			continue
		}
		el = append(el, Entry{fm.IsDir, p[0]})
	}
	return el
}