本文整理汇总了Golang中sourcegraph/com/sourcegraph/rwvfs.Sub函数的典型用法代码示例。如果您正苦于以下问题:Golang Sub函数的具体用法?Golang Sub怎么用?Golang Sub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sub函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: openUnitStore
func (s *fsTreeStore) openUnitStore(u unit.ID2) UnitStore {
filename := s.unitFilename(u.Type, u.Name)
dir := strings.TrimSuffix(filename, unitFileSuffix)
if useIndexedStore {
return newIndexedUnitStore(rwvfs.Sub(s.fs, dir), u.String())
}
return &fsUnitStore{fs: rwvfs.Sub(s.fs, dir), label: u.String()}
}
示例2: TestRWVFS
func TestRWVFS(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "rwvfs-test-")
if err != nil {
t.Fatal("TempDir", err)
}
defer os.RemoveAll(tmpdir)
h := http.Handler(rwvfs.HTTPHandler(rwvfs.Map(map[string]string{}), nil))
httpServer := httptest.NewServer(h)
defer httpServer.Close()
httpURL, err := url.Parse(httpServer.URL)
if err != nil {
t.Fatal(err)
}
tests := []struct {
fs rwvfs.FileSystem
}{
{rwvfs.OS(tmpdir)},
{rwvfs.Map(map[string]string{})},
{rwvfs.Sub(rwvfs.Map(map[string]string{}), "/x")},
{rwvfs.HTTP(httpURL, nil)},
{rwvfs.Union(rwvfs.Map(map[string]string{}), rwvfs.Map(map[string]string{}))},
}
for _, test := range tests {
testutil.Write(t, test.fs)
testutil.Mkdir(t, test.fs)
testutil.MkdirAll(t, test.fs)
testutil.Glob(t, test.fs)
}
}
示例3: TestSub_ReadLink
func TestSub_ReadLink(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "rwvfs-test-")
if err != nil {
t.Fatal("TempDir", err)
}
defer os.RemoveAll(tmpdir)
if err := os.Mkdir(filepath.Join(tmpdir, "mydir"), 0700); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(tmpdir, "mydir", "myfile"), []byte("hello"), 0600); err != nil {
t.Fatal(err)
}
if err := os.Symlink(filepath.Join(tmpdir, "mydir", "myfile"), filepath.Join(tmpdir, "mydir", "mylink")); err != nil {
t.Fatal(err)
}
osfs := rwvfs.OS(tmpdir)
sub := rwvfs.Sub(osfs, "mydir")
dst, err := sub.(rwvfs.LinkFS).ReadLink("mylink")
if err != nil {
t.Fatal(err)
}
if want := "myfile"; dst != want {
t.Errorf("%s: ReadLink: got %q, want %q", osfs, dst, want)
}
}
示例4: TestSub_Symlink
func TestSub_Symlink(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "rwvfs-test-")
if err != nil {
t.Fatal("TempDir", err)
}
//defer os.RemoveAll(tmpdir)
want := "hello"
if err := os.Mkdir(filepath.Join(tmpdir, "mydir"), 0700); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(tmpdir, "mydir", "myfile"), []byte(want), 0600); err != nil {
t.Fatal(err)
}
osfs := rwvfs.OS(tmpdir)
sub := rwvfs.Sub(osfs, "mydir")
if err := sub.(rwvfs.LinkFS).Symlink("myfile", "mylink"); err != nil {
t.Fatal(err, osfs)
}
got, err := ioutil.ReadFile(filepath.Join(tmpdir, "mydir", "mylink"))
if err != nil {
t.Fatal(err, osfs, sub)
}
if string(got) != want {
t.Errorf("%s: ReadLink: got %q, want %q", osfs, string(got), want)
}
}
示例5: TestMap_MkdirAllWithRootNotExists
func TestMap_MkdirAllWithRootNotExists(t *testing.T) {
m := map[string]string{}
fs := rwvfs.Sub(rwvfs.Map(m), "x")
paths := []string{"a/b", "/c/d"}
for _, path := range paths {
if err := rwvfs.MkdirAll(fs, path); err != nil {
t.Errorf("MkdirAll %q: %s", path, err)
}
}
}
示例6: newTestFS
func newTestFS() rwvfs.WalkableFileSystem {
switch *fsType {
case "map":
fs := rwvfs.Map(map[string]string{})
return rwvfs.Walkable(rwvfs.Sub(fs, "/testdata"))
case "os":
tmpDir, err := ioutil.TempDir("", "srclib-test")
if err != nil {
log.Fatal(err)
}
fs := rwvfs.OS(tmpDir)
setCreateParentDirs(fs)
return rwvfs.Walkable(fs)
default:
log.Fatalf("unrecognized -test.fs option: %q", *fsType)
panic("unreachable")
}
}
示例7: TestMap_Walk2
func TestMap_Walk2(t *testing.T) {
m := map[string]string{"a/b/c/d": "a"}
mapFS := rwvfs.Map(m)
var names []string
w := fs.WalkFS(".", rwvfs.Walkable(rwvfs.Sub(mapFS, "a/b")))
for w.Step() {
if err := w.Err(); err != nil {
t.Fatalf("walk path %q: %s", w.Path(), err)
}
names = append(names, w.Path())
}
wantNames := []string{".", "c", "c/d"}
sort.Strings(names)
sort.Strings(wantNames)
if !reflect.DeepEqual(names, wantNames) {
t.Errorf("got entry names %v, want %v", names, wantNames)
}
}
示例8: Commit
func (s *repoBuildStore) Commit(commitID string) rwvfs.WalkableFileSystem {
path := s.commitPath(commitID)
// Dereference path if path refers to a symlink, so that we can
// walk the tree.
e, _ := s.fs.Lstat(path)
if e != nil && e.Mode()&os.ModeSymlink != 0 {
if fs, ok := s.fs.(rwvfs.LinkFS); ok {
var err error
dst, err := fs.ReadLink(path)
if err == nil {
path = dst
} else if err == rwvfs.ErrOutsideRoot && FollowCrossFSSymlinks {
return rwvfs.Walkable(rwvfs.OS(dst))
} else {
log.Printf("Failed to read symlink %s: %s. Using non-dereferenced path.", path, err)
}
} else {
log.Printf("Repository build store path for commit %s is a symlink, but the current VFS %s doesn't support dereferencing symlinks.", commitID, s.fs)
}
}
return rwvfs.Walkable(rwvfs.Sub(s.fs, path))
}
示例9: TestSub
func TestSub(t *testing.T) {
m := rwvfs.Map(map[string]string{})
sub := rwvfs.Sub(m, "/sub")
err := sub.Mkdir("/")
if err != nil {
t.Fatal(err)
}
testutil.IsDir(t, "sub", m, "/sub")
f, err := sub.Create("f1")
f.Close()
if err != nil {
t.Fatal(err)
}
testutil.IsFile(t, "sub", m, "/sub/f1")
f, err = sub.Create("/f2")
f.Close()
if err != nil {
t.Fatal(err)
}
testutil.IsFile(t, "sub", m, "/sub/f2")
err = sub.Mkdir("/d1")
if err != nil {
t.Fatal(err)
}
testutil.IsDir(t, "sub", m, "/sub/d1")
err = sub.Mkdir("/d2")
if err != nil {
t.Fatal(err)
}
testutil.IsDir(t, "sub", m, "/sub/d2")
}
示例10: treeStoreFS
func (s *fsRepoStore) treeStoreFS(commitID string) rwvfs.FileSystem {
return rwvfs.Sub(s.fs, commitID)
}
示例11: openRepoStore
func (s *fsMultiRepoStore) openRepoStore(repo string) RepoStore {
subpath := s.fs.Join(s.RepoToPath(repo)...)
return NewFSRepoStore(rwvfs.Sub(s.fs, subpath))
}
示例12: RepoBuildStore
func (s *MultiStore) RepoBuildStore(repoURI string) (RepoBuildStore, error) {
path := filepath.Clean(string(repoURI))
return Repo(rwvfs.Walkable(rwvfs.Sub(s.fs, path))), nil
}