當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Clnt.FOpen方法代碼示例

本文整理匯總了Golang中github.com/mortdeus/go9p/clnt.Clnt.FOpen方法的典型用法代碼示例。如果您正苦於以下問題:Golang Clnt.FOpen方法的具體用法?Golang Clnt.FOpen怎麽用?Golang Clnt.FOpen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mortdeus/go9p/clnt.Clnt的用法示例。


在下文中一共展示了Clnt.FOpen方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: lsone

func lsone(c *clnt.Clnt, s string, long bool) {
	st, oserr := c.FStat(normpath(s))
	if oserr != nil {
		fmt.Fprintf(os.Stderr, "error stat: %v\n", oserr)
		return
	}
	if st.Mode&go9p.DMDIR != 0 {
		file, oserr := c.FOpen(s, go9p.OREAD)
		if oserr != nil {
			fmt.Fprintf(os.Stderr, "error opening dir: %s\n", oserr)
			return
		}
		defer file.Close()
		for {
			d, oserr := file.Readdir(0)
			if oserr != nil {
				fmt.Fprintf(os.Stderr, "error reading dir: %v\n", oserr)
			}
			if d == nil || len(d) == 0 {
				break
			}
			for _, dir := range d {
				if long {
					fmt.Fprintf(os.Stdout, "%s\n", dirtostr(dir))
				} else {
					os.Stdout.WriteString(dir.Name + "\n")
				}
			}
		}
	} else {
		fmt.Fprintf(os.Stdout, "%s\n", dirtostr(st))
	}
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:33,代碼來源:cl.go

示例2: Open

func (me *P9Fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {

	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var f []byte

	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = 0
	c, err = clnt.Mount("tcp", address, "", user)
	if err != nil {
		goto error
	}

	file, err = c.FOpen("/tmp/anaconda-post.log", go9p.OREAD)
	if err != nil {
		goto error
	}
	defer file.Close()
	f, err = ioutil.ReadAll(file)

	if err != nil && err != io.EOF {
		goto error
	}

	return nodefs.NewDataFile(f), fuse.OK

error:
	log.Println("Error", err)
	return nil, fuse.EPERM
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:32,代碼來源:main.go

示例3: main

func main() {
	var n, m int
	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var buf []byte

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", user)
	if err != nil {
		goto error
	}

	if flag.NArg() != 1 {
		log.Println("invalid arguments")
		return
	}

	file, err = c.FOpen(flag.Arg(0), go9p.OWRITE|go9p.OTRUNC)
	if err != nil {
		file, err = c.FCreate(flag.Arg(0), 0666, go9p.OWRITE)
		if err != nil {
			goto error
		}
	}

	buf = make([]byte, 8192)
	for {
		n, err = os.Stdin.Read(buf)
		if err != nil && err != io.EOF {
			goto error
		}

		if n == 0 {
			break
		}

		m, err = file.Write(buf[0:n])
		if err != nil {
			goto error
		}

		if m != n {
			err = &go9p.Error{"short write", 0}
			goto error
		}
	}

	file.Close()
	return

error:
	log.Println("Error", err)
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:57,代碼來源:write.go

示例4: cmdput

// Copy a local file to remote server
func cmdput(c *clnt.Clnt, s []string) {
	var from, to string
	switch len(s) {
	case 1:
		_, to = path.Split(s[0])
		to = normpath(to)
		from = s[0]
	case 2:
		from, to = s[0], normpath(s[1])
	default:
		fmt.Fprintf(os.Stderr, "incorrect arguments; usage: put local [remote]\n")
	}

	fromfile, err := os.Open(from)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error opening %s for reading: %s\n", from, err)
		return
	}
	defer fromfile.Close()

	file, ferr := c.FOpen(to, go9p.OWRITE|go9p.OTRUNC)
	if ferr != nil {
		file, ferr = c.FCreate(to, 0666, go9p.OWRITE)
		if ferr != nil {
			fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
			return
		}
	}
	defer file.Close()

	buf := make([]byte, 8192)
	for {
		n, oserr := fromfile.Read(buf)
		if oserr != nil && oserr != io.EOF {
			fmt.Fprintf(os.Stderr, "error reading %s: %s\n", from, oserr)
			return
		}

		if n == 0 {
			break
		}

		m, oserr := file.Write(buf[0:n])
		if oserr != nil {
			fmt.Fprintf(os.Stderr, "error writing %s: %v\n", to, oserr)
			return
		}

		if m != n {
			fmt.Fprintf(os.Stderr, "short write %s\n", to)
			return
		}
	}
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:55,代碼來源:cl.go

示例5: cmdget

// Copy a remote file to local filesystem
func cmdget(c *clnt.Clnt, s []string) {
	var from, to string
	switch len(s) {
	case 1:
		from = normpath(s[0])
		_, to = path.Split(s[0])
	case 2:
		from, to = normpath(s[0]), s[1]
	default:
		fmt.Fprintf(os.Stderr, "from arguments; usage: get from to\n")
	}

	tofile, err := os.Create(to)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
		return
	}
	defer tofile.Close()

	file, ferr := c.FOpen(from, go9p.OREAD)
	if ferr != nil {
		fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
		return
	}
	defer file.Close()

	buf := make([]byte, 8192)
	for {
		n, oserr := file.Read(buf)
		if oserr != nil {
			fmt.Fprintf(os.Stderr, "error reading %s: %s\n", from, oserr)
			return
		}
		if n == 0 {
			break
		}

		m, err := tofile.Write(buf[0:n])
		if err != nil {
			fmt.Fprintf(os.Stderr, "error writing %s: %s\n", to, err)
			return
		}

		if m != n {
			fmt.Fprintf(os.Stderr, "short write %s\n", to)
			return
		}
	}
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:50,代碼來源:cl.go

示例6: main

func main() {
	var n int
	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var buf []byte

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", user)
	if err != nil {
		goto error
	}

	if flag.NArg() != 1 {
		log.Println("invalid arguments")
		return
	}

	file, err = c.FOpen(flag.Arg(0), go9p.OREAD)
	if err != nil {
		goto error
	}

	buf = make([]byte, 8192)
	for {
		n, err = file.Read(buf)
		if n == 0 {
			break
		}

		os.Stdout.Write(buf[0:n])
	}

	file.Close()

	if err != nil && err != io.EOF {
		goto error
	}

	return

error:
	log.Println("Error", err)
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:47,代碼來源:read.go

示例7: main

func main() {
	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var d []*go9p.Dir

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", user)
	if err != nil {
		log.Fatal(err)
	}

	lsarg := "/"
	if flag.NArg() == 1 {
		lsarg = flag.Arg(0)
	} else if flag.NArg() > 1 {
		log.Fatal("error: only one argument expected")
	}

	file, err = c.FOpen(lsarg, go9p.OREAD)
	if err != nil {
		log.Fatal(err)
	}

	for {
		d, err = file.Readdir(0)
		if d == nil || len(d) == 0 || err != nil {
			break
		}

		for i := 0; i < len(d); i++ {
			os.Stdout.WriteString(d[i].Name + "\n")
		}
	}

	file.Close()
	if err != nil && err != io.EOF {
		log.Fatal(err)
	}

	return
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:45,代碼來源:ls.go

示例8: writeone

// Write the string s to remote file f. Create f if it doesn't exist
func writeone(c *clnt.Clnt, f, s string) {
	fname := normpath(f)
	file, oserr := c.FCreate(fname, 0666, go9p.OWRITE)
	if oserr != nil {
		file, oserr = c.FOpen(fname, go9p.OWRITE|go9p.OTRUNC)
		if oserr != nil {
			fmt.Fprintf(os.Stderr, "error opening %s: %v\n", fname, oserr)
			return
		}
	}
	defer file.Close()

	m, oserr := file.Write([]byte(s))
	if oserr != nil {
		fmt.Fprintf(os.Stderr, "error writing to %s: %v\n", fname, oserr)
		return
	}

	if m != len(s) {
		fmt.Fprintf(os.Stderr, "short write %s\n", fname)
		return
	}
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:24,代碼來源:cl.go

示例9: cmdcat

// Print the contents of f
func cmdcat(c *clnt.Clnt, s []string) {
	buf := make([]byte, 8192)
Outer:
	for _, f := range s {
		fname := normpath(f)
		file, oserr := c.FOpen(fname, go9p.OREAD)
		if oserr != nil {
			fmt.Fprintf(os.Stderr, "error opening %s: %v\n", f, oserr)
			continue Outer
		}
		defer file.Close()
		for {
			n, oserr := file.Read(buf)
			if oserr != nil && oserr != io.EOF {
				fmt.Fprintf(os.Stderr, "error reading %s: %v\n", f, oserr)
			}
			if n == 0 {
				break
			}
			os.Stdout.Write(buf[0:n])
		}
	}
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:24,代碼來源:cl.go


注:本文中的github.com/mortdeus/go9p/clnt.Clnt.FOpen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。