Example #1
0
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()}
}
Example #2
0
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)
	}
}
Example #3
0
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)
	}
}
Example #4
0
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)
	}
}
Example #5
0
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)
		}
	}
}
Example #6
0
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")
	}
}
Example #7
0
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)
	}
}
Example #8
0
File: store.go Project: xuy/srclib
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))
}
Example #9
0
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")
}
Example #10
0
func (s *fsRepoStore) treeStoreFS(commitID string) rwvfs.FileSystem {
	return rwvfs.Sub(s.fs, commitID)
}
Example #11
0
func (s *fsMultiRepoStore) openRepoStore(repo string) RepoStore {
	subpath := s.fs.Join(s.RepoToPath(repo)...)
	return NewFSRepoStore(rwvfs.Sub(s.fs, subpath))
}
Example #12
0
File: store.go Project: xuy/srclib
func (s *MultiStore) RepoBuildStore(repoURI string) (RepoBuildStore, error) {
	path := filepath.Clean(string(repoURI))
	return Repo(rwvfs.Walkable(rwvfs.Sub(s.fs, path))), nil
}