Example #1
0
// List returns a list of qp.Stats for each file in the directory. It does not
// verify if the file is a directory before trying to decode the content - the
// result will most likely be decoding errors.
func (c *SimpleClient) List(file string) ([]qp.Stat, error) {
	if c.root == nil {
		return nil, ErrSimpleClientNotStarted
	}
	fid, _, err := c.walkTo(file)
	if err != nil {
		return nil, err
	}
	defer fid.Clunk()
	_, _, err = fid.Open(qp.OREAD)
	if err != nil {
		return nil, err
	}

	sfid := &WrappedFid{Fid: fid}

	b, err := sfid.ReadAll()
	if err != nil {
		return nil, err
	}

	var stats []qp.Stat
	for len(b) > 0 {
		x := qp.Stat{}
		l := binary.LittleEndian.Uint16(b[0:2])
		if err := x.Unmarshal(b[0 : 2+l]); err != nil {
			return nil, err
		}
		b = b[2+l:]
		stats = append(stats, x)
	}

	return stats, nil
}
Example #2
0
func readdir(b []byte) ([]qp.Stat, error) {
	var stats []qp.Stat
	for len(b) > 0 {
		x := qp.Stat{}
		l := binary.LittleEndian.Uint16(b[0:2])
		if err := x.Unmarshal(b[0 : 2+l]); err != nil {
			return nil, err
		}
		b = b[2+l:]
		stats = append(stats, x)
	}

	return stats, nil
}
Example #3
0
// Readdir interprets a 9p2000 directory listing.
func Readdir(b []byte) ([]qp.Stat, error) {
	stats := make([]qp.Stat, 0, len(b)/64)
	for len(b) > 0 {
		l := int(binary.LittleEndian.Uint16(b[0:2]))
		if l+2 > len(b) {
			return stats, errors.New("short input")
		}

		var stat qp.Stat
		if err := stat.Unmarshal(b[0 : 2+l]); err != nil {
			return stats, err
		}
		b = b[2+l:]
		stats = append(stats, stat)
	}

	return stats, nil
}