本文整理匯總了Golang中github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/rwvfs.FileSystem.Stat方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem.Stat方法的具體用法?Golang FileSystem.Stat怎麽用?Golang FileSystem.Stat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/rwvfs.FileSystem
的用法示例。
在下文中一共展示了FileSystem.Stat方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: 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)
}
}
示例3: 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)
}
}
示例4: 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")
}
示例5: 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))
}