Esempio n. 1
0
func (w *testWriter) Close() error {
	p := w.p
	desc := p.desc

	desc.Lock()
	desc.print(fmt.Sprintf("testDesc: closing writer, num=%d type=%s", p.num, p.t))
	p.opened = false
	desc.Unlock()

	return nil
}
Esempio n. 2
0
func (p *testFilePtr) Remove() error {
	desc := p.desc

	desc.Lock()
	defer desc.Unlock()

	desc.print(fmt.Sprintf("testDesc: removing file, num=%d type=%s", p.num, p.t))

	if f, exist := desc.files[p.id()]; exist {
		if f.opened {
			return errFileOpen
		}
		f.buf.Reset()
		delete(desc.files, p.id())
	}

	return nil
}
Esempio n. 3
0
func (p *testFilePtr) Open() (r desc.Reader, err error) {
	desc := p.desc

	desc.Lock()
	defer desc.Unlock()

	desc.print(fmt.Sprintf("testDesc: open file, num=%d type=%s", p.num, p.t))

	f, exist := desc.files[p.id()]
	if !exist {
		return nil, os.ErrNotExist
	}

	if f.opened {
		return nil, errFileOpen
	}

	f.opened = true
	r = &testReader{f, bytes.NewReader(f.buf.Bytes())}
	return
}
Esempio n. 4
0
func (p *testFilePtr) Create() (w desc.Writer, err error) {
	desc := p.desc

	desc.Lock()
	defer desc.Unlock()

	desc.print(fmt.Sprintf("testDesc: create file, num=%d type=%s", p.num, p.t))

	f, exist := desc.files[p.id()]
	if exist {
		if f.opened {
			return nil, errFileOpen
		}
	} else {
		f = &testFile{desc: desc, num: p.num, t: p.t}
		desc.files[p.id()] = f
	}

	f.opened = true
	f.buf.Reset()
	return &testWriter{f}, nil
}
Esempio n. 5
0
func (p *testFilePtr) Rename(num uint64, t desc.FileType) error {
	desc := p.desc

	desc.Lock()
	defer desc.Unlock()

	desc.print(fmt.Sprintf("testDesc: rename file, from num=%d type=%s, to num=%d type=%d", p.num, p.t, num, t))

	oid := p.id()
	p.num = num
	p.t = t

	if f, exist := desc.files[oid]; exist {
		if f.opened {
			return errFileOpen
		}
		delete(desc.files, oid)
		f.num = num
		f.t = t
		desc.files[p.id()] = f
	}

	return nil
}