Пример #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()}
}
Пример #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
		path string
	}{
		{rwvfs.OS(tmpdir), "/foo"},
		{rwvfs.Map(map[string]string{}), "/foo"},
		{rwvfs.Sub(rwvfs.Map(map[string]string{}), "/x"), "/foo"},
		{rwvfs.HTTP(httpURL, nil), "/foo"},
	}
	for _, test := range tests {
		testWrite(t, test.fs, test.path)
		testMkdir(t, test.fs)
		testMkdirAll(t, test.fs)
		testGlob(t, test.fs)
	}
}
Пример #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)
	}
}
Пример #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)
	}
}
Пример #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)
		}
	}
}
Пример #6
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)
	}
}
Пример #7
0
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))
}
Пример #8
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)
	}
	testIsDir(t, "sub", m, "/sub")

	f, err := sub.Create("f1")
	f.Close()
	if err != nil {
		t.Fatal(err)
	}
	testIsFile(t, "sub", m, "/sub/f1")

	f, err = sub.Create("/f2")
	f.Close()
	if err != nil {
		t.Fatal(err)
	}
	testIsFile(t, "sub", m, "/sub/f2")

	err = sub.Mkdir("/d1")
	if err != nil {
		t.Fatal(err)
	}
	testIsDir(t, "sub", m, "/sub/d1")

	err = sub.Mkdir("/d2")
	if err != nil {
		t.Fatal(err)
	}
	testIsDir(t, "sub", m, "/sub/d2")
}
Пример #9
0
func (s *MultiStore) RepoBuildStore(repoURI string) (RepoBuildStore, error) {
	path := filepath.Clean(string(repoURI))
	return Repo(rwvfs.Walkable(rwvfs.Sub(s.fs, path))), nil
}
Пример #10
0
func (s *fsRepoStore) treeStoreFS(commitID string) rwvfs.FileSystem {
	return rwvfs.Sub(s.fs, commitID)
}
Пример #11
0
func (s *fsMultiRepoStore) openRepoStore(repo string) RepoStore {
	subpath := s.fs.Join(s.RepoToPath(repo)...)
	return NewFSRepoStore(rwvfs.Sub(s.fs, subpath))
}