Esempio n. 1
0
// Return bytes written, resulting content, and any error.
func write(conn *client.Conn, username, filepath, contents string) (int, string, error) {

	fsys, err := conn.Attach(nil, username, "/")

	if err != nil {
		return 0, "", err
	}

	fid, err := fsys.Open(filepath, plan9.OWRITE)

	if err != nil {
		return 0, "", err
	}

	defer fid.Close()

	n, err := fid.Write([]byte("whom"))

	if err != nil {
		return n, "", err
	}

	newcontents, err := ioutil.ReadFile(rootdir + "/" + filepath)

	return n, string(newcontents), err

}
Esempio n. 2
0
func read(conn *client.Conn, username, filepath string) (string, error) {

	fsys, err := conn.Attach(nil, username, "/")

	if err != nil {
		return "", err
	}

	fid, err := fsys.Open(filepath, plan9.OREAD)

	if err != nil {
		return "", err
	}
	defer fid.Close()

	var buf []byte
	if fid.Qid().Type&plan9.QTDIR != 0 {
		buf, err = readDir(fid)
	} else {
		buf, err = ioutil.ReadAll(fid)
	}

	return string(buf), err

}
Esempio n. 3
0
// Return owner and group of given file.
func usergroup(conn *client.Conn, filepath string) (string, string, error) {

	fsys, err := conn.Attach(nil, "adm", "/")

	if err != nil {
		return "", "", err
	}

	dir, err := fsys.Stat(filepath)

	if err != nil {
		return "", "", err
	}

	return dir.Uid, dir.Gid, nil
}
Esempio n. 4
0
// Create file or directory.
func create(conn *client.Conn, username, filepath string, mode os.FileMode) error {

	fsys, err := conn.Attach(nil, username, "/")

	if err != nil {
		return err
	}

	fid, err := fsys.Create(filepath, plan9.OREAD, plan9.Perm(mode))

	if err != nil {
		return err
	}

	fid.Close()

	return nil
}