本文整理汇总了Golang中github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/rwvfs.FileSystem类的典型用法代码示例。如果您正苦于以下问题:Golang FileSystem类的具体用法?Golang FileSystem怎么用?Golang FileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSystem类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: readIndex
// readIndex calls x.Read with the index's backing file.
func readIndex(fs rwvfs.FileSystem, name string, x persistedIndex) (err error) {
vlog.Printf("%s: reading index...", name)
var f vfs.ReadSeekCloser
f, err = fs.Open(fmt.Sprintf(indexFilename, name))
if err != nil {
vlog.Printf("%s: failed to read index: %s.", name, err)
if os.IsNotExist(err) {
return &errIndexNotExist{name: name, err: err}
}
return err
}
defer func() {
err2 := f.Close()
if err == nil {
err = err2
}
}()
r, err := gzip.NewReader(f)
if err != nil {
return err
}
if err := x.Read(r); err != nil {
return err
}
if err := r.Close(); err != nil {
return err
}
vlog.Printf("%s: done reading index.", name)
return nil
}
开发者ID:sombr,项目名称:ccat,代码行数:33,代码来源:indexed.go
示例2: writeIndex
// writeIndex calls x.Write with the index's backing file.
func writeIndex(fs rwvfs.FileSystem, name string, x persistedIndex) (err error) {
vlog.Printf("%s: writing index...", name)
f, err := fs.Create(fmt.Sprintf(indexFilename, name))
if err != nil {
return err
}
defer func() {
err2 := f.Close()
if err == nil {
err = err2
}
}()
w := gzip.NewWriter(f)
if err := x.Write(w); err != nil {
return err
}
if err := w.Flush(); err != nil {
return err
}
if err := w.Close(); err != nil {
return err
}
vlog.Printf("%s: done writing index.", name)
return nil
}
开发者ID:sombr,项目名称:ccat,代码行数:28,代码来源:indexed.go
示例3: testWrite
func testWrite(t *testing.T, fs rwvfs.FileSystem, path string) {
label := fmt.Sprintf("%T", fs)
w, err := fs.Create(path)
if err != nil {
t.Fatalf("%s: WriterOpen: %s", label, err)
}
input := []byte("qux")
_, err = w.Write(input)
if err != nil {
t.Fatalf("%s: Write: %s", label, err)
}
err = w.Close()
if err != nil {
t.Fatalf("%s: w.Close: %s", label, err)
}
var r io.ReadCloser
r, err = fs.Open(path)
if err != nil {
t.Fatalf("%s: Open: %s", label, err)
}
var output []byte
output, err = ioutil.ReadAll(r)
if err != nil {
t.Fatalf("%s: ReadAll: %s", label, err)
}
if !bytes.Equal(output, input) {
t.Errorf("%s: got output %q, want %q", label, output, input)
}
r, err = fs.Open(path)
if err != nil {
t.Fatalf("%s: Open: %s", label, err)
}
output, err = ioutil.ReadAll(r)
if err != nil {
t.Fatalf("%s: ReadAll: %s", label, err)
}
if !bytes.Equal(output, input) {
t.Errorf("%s: got output %q, want %q", label, output, input)
}
err = fs.Remove(path)
if err != nil {
t.Errorf("%s: Remove(%q): %s", label, path, err)
}
testPathDoesNotExist(t, label, fs, path)
}
开发者ID:sombr,项目名称:ccat,代码行数:51,代码来源:vfs_test.go
示例4: setCreateParentDirs
func setCreateParentDirs(fs rwvfs.FileSystem) {
type createParents interface {
CreateParentDirs(bool)
}
if fs, ok := fs.(createParents); ok {
fs.CreateParentDirs(true)
}
}
开发者ID:sombr,项目名称:ccat,代码行数:8,代码来源:store.go
示例5: testPathDoesNotExist
func testPathDoesNotExist(t *testing.T, label string, fs rwvfs.FileSystem, path string) {
fi, err := fs.Stat(path)
if err != nil && !os.IsNotExist(err) {
t.Errorf("%s: Stat(%q): want os.IsNotExist-satisfying error, got %q", label, path, err)
} else if err == nil {
t.Errorf("%s: Stat(%q): want file to not exist, got existing file with FileInfo %+v", label, path, fi)
}
}
开发者ID:sombr,项目名称:ccat,代码行数:8,代码来源:vfs_test.go
示例6: testIsFile
func testIsFile(t *testing.T, label string, fs rwvfs.FileSystem, path string) {
fi, err := fs.Stat(path)
if err != nil {
t.Fatalf("%s: Stat(%q): %s", label, path, err)
}
if !fi.Mode().IsRegular() {
t.Errorf("%s: got fs.Stat(%q) Mode().IsRegular() == false, want true", label, path)
}
}
开发者ID:sombr,项目名称:ccat,代码行数:10,代码来源:vfs_test.go
示例7: uploadFile
func uploadFile(local vfs.FileSystem, remote rwvfs.FileSystem, path string, fi os.FileInfo, dryRun bool) error {
kb := float64(fi.Size()) / 1024
if GlobalOpt.Verbose || dryRun {
log.Printf("Uploading %s (%.1fkb)", path, kb)
}
if dryRun {
return nil
}
lf, err := local.Open(path)
if err != nil {
return err
}
if err := rwvfs.MkdirAll(remote, filepath.Dir(path)); err != nil {
return err
}
rf, err := remote.Create(path)
if err != nil {
return err
}
defer func() {
if err := rf.Close(); err != nil {
log.Println("Error closing after error:", err)
}
}()
if _, err := io.Copy(rf, lf); err != nil {
return err
}
if err := rf.Close(); err != nil {
return err
}
if GlobalOpt.Verbose {
log.Printf("Uploaded %s (%.1fkb)", path, kb)
}
return nil
}
开发者ID:sombr,项目名称:ccat,代码行数:40,代码来源:build_data_cmds.go
示例8: fetchFile
func fetchFile(remote vfs.FileSystem, local rwvfs.FileSystem, path string, fi os.FileInfo, dryRun bool) error {
kb := float64(fi.Size()) / 1024
if GlobalOpt.Verbose || dryRun {
log.Printf("Fetching %s (%.1fkb)", path, kb)
}
if dryRun {
return nil
}
if err := rwvfs.MkdirAll(local, filepath.Dir(path)); err != nil {
return err
}
rf, err := remote.Open(path)
if err != nil {
return fmt.Errorf("remote file: %s", err)
}
defer rf.Close()
lf, err := local.Create(path)
if err != nil {
return fmt.Errorf("local file: %s", err)
}
defer lf.Close()
if _, err := io.Copy(lf, rf); err != nil {
return fmt.Errorf("copy from remote to local: %s", err)
}
if GlobalOpt.Verbose {
log.Printf("Fetched %s (%.1fkb)", path, kb)
}
if err := lf.Close(); err != nil {
return fmt.Errorf("local file: %s", err)
}
return nil
}
开发者ID:sombr,项目名称:ccat,代码行数:38,代码来源:build_data_cmds.go
示例9: testIsDir
func testIsDir(t *testing.T, label string, fs rwvfs.FileSystem, path string) {
fi, err := fs.Stat(path)
if err != nil {
t.Fatalf("%s: Stat(%q): %s", label, path, err)
}
if fi == nil {
t.Fatalf("%s: FileInfo (%q) == nil", label, path)
}
if !fi.IsDir() {
t.Errorf("%s: got fs.Stat(%q) IsDir() == false, want true", label, path)
}
}
开发者ID:sombr,项目名称:ccat,代码行数:14,代码来源:vfs_test.go
示例10: rangeReader
// rangeReader calls ioutil.ReadAll on the given byte range [start, n). It uses
// optimizations for different kinds of VFSs.
func rangeReader(fs rwvfs.FileSystem, name string, f io.ReadSeeker, start, n int64) (io.Reader, error) {
if fs, ok := fs.(rwvfs.FetcherOpener); ok {
// Clone f so we can parallelize it.
var err error
f, err = fs.OpenFetcher(name)
if err != nil {
return nil, err
}
if err := f.(rwvfs.Fetcher).Fetch(start, start+n); err != nil {
return nil, err
}
}
if _, err := f.Seek(start, 0); err != nil {
return nil, err
}
return f, nil
}
开发者ID:sombr,项目名称:ccat,代码行数:19,代码来源:fs_store.go
示例11: testGlob
func testGlob(t *testing.T, fs rwvfs.FileSystem) {
label := fmt.Sprintf("%T", fs)
files := []string{"x/y/0.txt", "x/y/1.txt", "x/2.txt"}
for _, file := range files {
err := rwvfs.MkdirAll(fs, filepath.Dir(file))
if err != nil {
t.Fatalf("%s: MkdirAll: %s", label, err)
}
w, err := fs.Create(file)
if err != nil {
t.Errorf("%s: Create(%q): %s", label, file, err)
return
}
w.Close()
}
globTests := []struct {
prefix string
pattern string
matches []string
}{
{"", "x/y/*.txt", []string{"x/y/0.txt", "x/y/1.txt"}},
{"x/y", "x/y/*.txt", []string{"x/y/0.txt", "x/y/1.txt"}},
{"", "x/*", []string{"x/y", "x/2.txt"}},
}
for _, test := range globTests {
matches, err := rwvfs.Glob(rwvfs.Walkable(fs), test.prefix, test.pattern)
if err != nil {
t.Errorf("%s: Glob(prefix=%q, pattern=%q): %s", label, test.prefix, test.pattern, err)
continue
}
sort.Strings(test.matches)
sort.Strings(matches)
if !reflect.DeepEqual(matches, test.matches) {
t.Errorf("%s: Glob(prefix=%q, pattern=%q): got %v, want %v", label, test.prefix, test.pattern, matches, test.matches)
}
}
}
开发者ID:sombr,项目名称:ccat,代码行数:39,代码来源:vfs_test.go
示例12: testMkdir
func testMkdir(t *testing.T, fs rwvfs.FileSystem) {
label := fmt.Sprintf("%T", fs)
if strings.Contains(label, "subFS") {
if err := fs.Mkdir("/"); err != nil && !os.IsExist(err) {
t.Fatalf("%s: subFS Mkdir(/): %s", label, err)
}
}
if strings.Contains(label, "mapFS") {
if err := fs.Mkdir("/"); err != nil && !os.IsExist(err) {
t.Fatalf("%s: mapFS Mkdir(/): %s", label, err)
}
}
fi, err := fs.Stat(".")
if err != nil {
t.Fatalf("%s: Stat(.): %s", label, err)
}
if !fi.Mode().IsDir() {
t.Fatalf("%s: got Stat(.) FileMode %o, want IsDir", label, fi.Mode())
}
fi, err = fs.Stat("/")
if err != nil {
t.Fatalf("%s: Stat(/): %s", label, err)
}
if !fi.Mode().IsDir() {
t.Fatalf("%s: got Stat(/) FileMode %o, want IsDir", label, fi.Mode())
}
if _, err := fs.ReadDir("."); err != nil {
t.Fatalf("%s: ReadDir(.): %s", label, err)
}
if _, err := fs.ReadDir("/"); err != nil {
t.Fatalf("%s: ReadDir(/): %s", label, err)
}
fis, err := fs.ReadDir("/")
if err != nil {
t.Fatalf("%s: ReadDir(/): %s", label, err)
}
if len(fis) != 0 {
t.Fatalf("%s: ReadDir(/): got %d file infos (%v), want none (is it including .?)", label, len(fis), fis)
}
err = fs.Mkdir("dir0")
if err != nil {
t.Fatalf("%s: Mkdir(dir0): %s", label, err)
}
testIsDir(t, label, fs, "dir0")
testIsDir(t, label, fs, "/dir0")
err = fs.Mkdir("/dir1")
if err != nil {
t.Fatalf("%s: Mkdir(/dir1): %s", label, err)
}
testIsDir(t, label, fs, "dir1")
testIsDir(t, label, fs, "/dir1")
err = fs.Mkdir("/dir1")
if !os.IsExist(err) {
t.Errorf("%s: Mkdir(/dir1) again: got err %v, want os.IsExist-satisfying error", label, err)
}
err = fs.Mkdir("/parent-doesnt-exist/dir2")
if !os.IsNotExist(err) {
t.Errorf("%s: Mkdir(/parent-doesnt-exist/dir2): got error %v, want os.IsNotExist-satisfying error", label, err)
}
err = fs.Remove("/dir1")
if err != nil {
t.Errorf("%s: Remove(/dir1): %s", label, err)
}
testPathDoesNotExist(t, label, fs, "/dir1")
}
开发者ID:sombr,项目名称:ccat,代码行数:75,代码来源:vfs_test.go
示例13: statIndex
// statIndex calls fs.Stat on the index's backing file or dir.
func statIndex(fs rwvfs.FileSystem, name string) (os.FileInfo, error) {
return fs.Stat(fmt.Sprintf(indexFilename, name))
}
开发者ID:sombr,项目名称:ccat,代码行数:4,代码来源:indexed.go
示例14: openFetcherOrOpen
// openFetcher calls fs.OpenFetcher if it implemented the
// FetcherOpener interface; otherwise it calls fs.Open.
func openFetcherOrOpen(fs rwvfs.FileSystem, name string) (vfs.ReadSeekCloser, error) {
if fo, ok := fs.(rwvfs.FetcherOpener); ok {
return fo.OpenFetcher(name)
}
return fs.Open(name)
}
开发者ID:sombr,项目名称:ccat,代码行数:8,代码来源:fs_store.go
注:本文中的github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/rwvfs.FileSystem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论