Пример #1
0
func oldwalk(name string) {
	fid, err := fs.Open(name, g9p.OREAD)
	if err != nil {
		fmt.Fprintf(os.Stderr, "cannot open %q: %v\n", name, err)
		return
	}
	defer fid.Close()
	if fid.Qid().Type&g9p.QTDIR != 0 {
		data, err := ioutil.ReadAll(fid)
		if err != nil {
			fmt.Fprintf(os.Stderr, "read %d bytes from %q: %v", len(data), err)
			return
		}
		d, err := g9p.UnmarshalDirs(data)
		if err != nil {
			fmt.Fprintf(os.Stderr, "cannot unpack directory %s: %v\n", name, err)
			return
		}
		for _, dir := range d {
			oldwalk(name + "/" + dir.Name)
		}
		return
	}
	sum <- count(fid)
}
Пример #2
0
func (fid *Fid) Dirreadall() ([]*plan9.Dir, error) {
	checkSeq(nil, fid)
	buf, err := ioutil.ReadAll(fid)
	if len(buf) == 0 {
		return nil, err
	}
	return plan9.UnmarshalDirs(buf)
}
Пример #3
0
func (fid *Fid) Dirread() ([]*plan9.Dir, error) {
	checkSeq(nil, fid)
	buf := make([]byte, plan9.STATMAX)
	n, err := fid.Read(buf)
	if err != nil {
		return nil, err
	}
	return plan9.UnmarshalDirs(buf[0:n])
}
Пример #4
0
func (f *NsFile) Dirread() ([]*plan9.Dir, error) {
	if !f.IsDir() {
		return nil, errors.New("not a directory")
	}
	buf := make([]byte, plan9.STATMAX)
	n, err := f.Read(buf)
	if err != nil {
		return nil, err
	}
	return plan9.UnmarshalDirs(buf[0:n])
}
Пример #5
0
func newwalk(name string, isDir bool) {
	r := ns.ReadStream(name, 20, 8192)
	if isDir {
		data, err := ioutil.ReadAll(r)
		if err != nil {
			fmt.Fprintf(os.Stderr, "read %d bytes from %q: %v", len(data), err)
			return
		}
		d, err := g9p.UnmarshalDirs(data)
		if err != nil {
			fmt.Fprintf(os.Stderr, "cannot unpack directory %s: %v\n", name, err)
			return
		}
		for _, dir := range d {
			newwalk(name+"/"+dir.Name, dir.Qid.Type&g9p.QTDIR != 0)
		}
		return
	}
	sum <- count(r)
}
Пример #6
0
func (t *traverser) readDir(pseq *seq.Sequencer, fid *g9pc.NsFile, path string) {
	t.printf("readDir %s", path)
	sq, results := pseq.Subsequencer("readDir")
	errc := make(chan error, 1)
	go func() {
		<-results          // SeqWalk (clone)
		_, ok := <-results // OpenReq
		if !ok {
			errc <- fmt.Errorf("cannot open %q: %#v", path, sq.Error())
			return
		}
		<-results // NonseqReq
		<-results // ReadStream
		errc <- nil
		_, ok = <-results // eof
		if ok {
			panic("expected closed")
		}
		errc <- nil
	}()

	rfid := fid.SeqWalk(sq)
	//	defer rfid.Close()		TODO something better!

	sq.Do(rfid.File(), seq.OpenReq{g9p.OREAD})
	sq.Do(fid.File(), seq.NonseqReq{})
	rd := rfid.SeqReadStream(sq, 5, 8192)
	defer rd.Close()

	buf, _ := ioutil.ReadAll(rd)
	t.printf("read %d bytes from %q", len(buf), path)
	err := <-errc
	sq.Do(nil, nil)
	<-errc
	//we get here but fid still can be part of the sequence.
	//maybe that means that subsequence has not terminated
	//correctly. no it doesn't. it means that the overall sequence
	//has not terminated correctly.
	//
	//question: should files opened as part of a subsequence be
	//ratified by the subsequence finishing?
	//only

	if err != nil && len(buf) == 0 {
		sq.Result(nil, err)
		t.printf("error on %s: %v\n", path, err)
		return
	}

	d, err := g9p.UnmarshalDirs(buf)
	if err != nil {
		t.printf("cannot unpack directory %s: %v\n", path, err)
		return
	}

	sync := make(chan bool)
	for i, dir := range d {
		t.printf("%q[%d]: %v", path, i, dir)
		go t.traverse(fid, path, dir.Name, sync)
	}
	for i := 0; i < len(d); i++ {
		<-sync
	}
	t.printf("%s: %d entries", path, len(d))
	sq.Result(seq.StringResult("readDir"), nil)
}