Skip to content

Commit

Permalink
Rel + update go version
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Jan 14, 2023
1 parent bf14a11 commit 84365b8
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 205 deletions.
15 changes: 11 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
module github.com/mandelsoft/vfs

go 1.13
go 1.19

require (
github.com/b4b4r07/go-pipe v0.0.0-20191010045404-84b446f57366 // indirect
github.com/joncalhoun/pipe v0.0.0-20170510025636-72505674a733 // indirect
github.com/mandelsoft/filepath v0.0.0-20200909114706-3df73d378d55
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
gopkg.in/pipe.v2 v2.0.0-20140414041502-3c2ca4d52544 // indirect
gopkg.in/yaml.v2 v2.3.0
)

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/nxadm/tail v1.4.4 // indirect
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 // indirect
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)
21 changes: 3 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/b4b4r07/go-pipe v0.0.0-20191010045404-84b446f57366 h1:FVAkDbBxovi2ID0vaxY7vCGvdKASt9r0TGPM1u4YQyg=
github.com/b4b4r07/go-pipe v0.0.0-20191010045404-84b446f57366/go.mod h1:1ymsiQNa3qebVEEVtuIdhtAXRfjO4qFCFq1bBUOT2HE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
Expand All @@ -9,25 +7,12 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/joncalhoun/pipe v0.0.0-20170510025636-72505674a733 h1:/wtaMDeVpoAUkqZl/GT3lvM9nDBmRApu/Uvl7EUc9Ao=
github.com/joncalhoun/pipe v0.0.0-20170510025636-72505674a733/go.mod h1:2MNFZhLx2HMHTN4xKH6FhpoQWqmD8Ato8QOE2hp5hY4=
github.com/mandelsoft/filepath v0.0.0-20180115145118-e79b4e7be206 h1:M02UJfGz1+m1oecAZ0JR3vtYmIHWGjzeiB979dDYrD0=
github.com/mandelsoft/filepath v0.0.0-20180115145118-e79b4e7be206/go.mod h1:EG0hGSztMG2F0cd5TYTQeCCB2hSJIAom3QuR7zgKMzE=
github.com/mandelsoft/filepath v0.0.0-20200901163143-eceff1ab880a h1:MrULybu0xBqZb/VfEJNnyhkBBmBLZ4iKsWhYIfV18YE=
github.com/mandelsoft/filepath v0.0.0-20200901163143-eceff1ab880a/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/filepath v0.0.0-20200902101319-250992c6d448 h1:RQbY8byTpeQFPULWbWQ2QqmgaAvK3v7Rpt+XnrlccP8=
github.com/mandelsoft/filepath v0.0.0-20200902101319-250992c6d448/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/filepath v0.0.0-20200902151426-f6fe988ac4aa h1:DgGRipjIJrFlbU9AD8h2s58oXE+MwcJP9hNNe+sjIug=
github.com/mandelsoft/filepath v0.0.0-20200902151426-f6fe988ac4aa/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/filepath v0.0.0-20200906144341-f6f7308759ed h1:yu9MpVjXEvfTAmhZFKHAgVVYgSn9D7N9VHn/3/XsXDo=
github.com/mandelsoft/filepath v0.0.0-20200906144341-f6f7308759ed/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/filepath v0.0.0-20200908104906-2d4df9739918 h1:bK6zU2n99z3vZo4gKOiUs5sG4sLCkYEetGVmPphv8k0=
github.com/mandelsoft/filepath v0.0.0-20200908104906-2d4df9739918/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/mandelsoft/filepath v0.0.0-20200909114706-3df73d378d55 h1:mFdiUG86O2iW+iDEpZKXf64efMWO4JvDT+zN3znUGIc=
github.com/mandelsoft/filepath v0.0.0-20200909114706-3df73d378d55/go.mod h1:n4xEiUD2HNHnn2w5ZKF0qgjDecHVCWAl5DxZ7+pcFU8=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
Expand Down Expand Up @@ -63,11 +48,11 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/pipe.v2 v2.0.0-20140414041502-3c2ca4d52544 h1:WJH1qsOB4/zb/li+zLMn0vaAUJ5FqPv6HYLI3aQVg1k=
gopkg.in/pipe.v2 v2.0.0-20140414041502-3c2ca4d52544/go.mod h1:UhTeH/yXCK/KY7TX24mqPkaQ7gZeqmWd/8SSS8B3aHw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 2 additions & 0 deletions pkg/vfs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type VFS interface {

Join(elems ...string) string
Split(path string) (string, string)
Components(path string) (string, []string)
Base(path string) string
Dir(path string) string
Clean(path string) string
Expand All @@ -177,6 +178,7 @@ type VFS interface {

Canonical(path string, exist bool) (string, error)
Abs(path string) (string, error)
Rel(src, tgt string) (string, error)
EvalSymlinks(path string) (string, error)
Walk(path string, fn WalkFunc) error

Expand Down
66 changes: 60 additions & 6 deletions pkg/vfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package vfs
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"path"
Expand Down Expand Up @@ -60,12 +61,12 @@ func Join(fs FileSystem, elems ...string) string {
// by purely lexical processing. It applies the following rules
// iteratively until no further processing can be done:
//
// 1. Replace multiple path separators with a single one.
// 2. Eliminate each . path name element (the current directory).
// 3. Eliminate each inner .. path name element (the parent directory)
// along with the non-.. element that precedes it.
// 4. Eliminate .. elements that begin a rooted path:
// that is, replace "/.." by "/" at the beginning of a path.
// 1. Replace multiple path separators with a single one.
// 2. Eliminate each . path name element (the current directory).
// 3. Eliminate each inner .. path name element (the parent directory)
// along with the non-.. element that precedes it.
// 4. Eliminate .. elements that begin a rooted path:
// that is, replace "/.." by "/" at the beginning of a path.
//
// The returned path ends in a slash only if it is the root "/".
//
Expand Down Expand Up @@ -267,6 +268,59 @@ func Abs(fs FileSystem, path string) (string, error) {
return Join(fs, p, path), nil
}

func Rel(fs FileSystem, src, tgt string) (string, error) {
s, err := Canonical(fs, src, false)
if err != nil {
return "", fmt.Errorf("%s: %w", src, err)
}

t, err := Canonical(fs, tgt, false)
if err != nil {
return "", fmt.Errorf("%s: %w", tgt, err)
}

vs, sseq := Components(fs, s)
vt, tseq := Components(fs, t)
if vs != vt {
return "", fmt.Errorf("different volumes")
}

if s == t {
return ".", nil
}
var is int
for is = 0; is < len(sseq); is++ {
if len(tseq) <= is || tseq[is] != sseq[is] {
break
}
}

for i := is; i < len(sseq); i++ {
sseq[i] = ".."
}

if is < len(tseq) {
return Join(fs, append(sseq[is:], tseq[is:]...)...), nil
}
return Join(fs, sseq[is:]...), nil
}

func Components(fs FileSystem, p string) (string, []string) {
var seq []string
var b string

v, p := SplitVolume(fs, p)

for !IsRoot(fs, p) {
p, b = Split(fs, p)
seq = append(seq, b)
}
for i := 0; i < len(seq)/2; i++ {
seq[i], seq[len(seq)-i-1] = seq[len(seq)-i-1], seq[i]
}
return v, seq
}

// Split splits path immediately following the final Separator,
// separating it into a directory and file name component.
// If there is no Separator in path, Split returns an empty dir
Expand Down
8 changes: 8 additions & 0 deletions pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func (fs *vfs) Abs(path string) (string, error) {
return Abs(fs, path)
}

func (fs *vfs) Rel(src, tgt string) (string, error) {
return Rel(fs, src, tgt)
}

func (fs *vfs) Components(path string) (string, []string) {
return Components(fs, path)
}

func (fs *vfs) EvalSymlinks(path string) (string, error) {
return EvalSymlinks(fs, path)
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/vfs/vfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ var _ = Describe("filesystem", func() {
})
})

Context("Rel", func() {
It("sub path", func() {
Expect(fs.Rel("/", "/sub")).To(Equal("sub"))
Expect(fs.Rel("/", "/sub/dir")).To(Equal("sub/dir"))
Expect(fs.Rel("/", "/sub/dir/file")).To(Equal("sub/dir/file"))
Expect(fs.Rel("sub", "sub/dir")).To(Equal("dir"))
Expect(fs.Rel("sub", "sub/dir/file")).To(Equal("dir/file"))
})

It("parent path", func() {
Expect(fs.Rel("/sub", "/")).To(Equal(".."))
Expect(fs.Rel("/sub/dir", "/")).To(Equal("../.."))
Expect(fs.Rel("/sub/dir/file", "/")).To(Equal("../../.."))
Expect(fs.Rel("sub/dir", "sub")).To(Equal(".."))
Expect(fs.Rel("sub/dir/file", "sub")).To(Equal("../.."))
})

It("common parent", func() {
Expect(fs.Rel("/sub/dir", "/sub/file")).To(Equal("../file"))
Expect(fs.Rel("/sub/dir/file", "/sub/dir2/file")).To(Equal("../../dir2/file"))
})

})
})

Context("eval sym links", func() {
Expand Down
5 changes: 0 additions & 5 deletions vendor/github.com/fsnotify/fsnotify/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/fsnotify/fsnotify/go.sum

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/nxadm/tail/go.mod

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/nxadm/tail/go.sum

This file was deleted.

11 changes: 0 additions & 11 deletions vendor/github.com/onsi/ginkgo/go.mod

This file was deleted.

67 changes: 0 additions & 67 deletions vendor/github.com/onsi/ginkgo/go.sum

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/onsi/gomega/go.mod

This file was deleted.

Loading

0 comments on commit 84365b8

Please sign in to comment.