File tree Expand file tree Collapse file tree 4 files changed +25
-9
lines changed Expand file tree Collapse file tree 4 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ require (
17
17
github.com/spf13/pflag v1.0.5
18
18
github.com/stretchr/testify v1.8.4
19
19
github.com/umlx5h/go-runewidth v0.0.0-20240106112317-9bbbb3702d5f
20
- github.com/yookoala/realpath v1.0.0
21
20
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
22
21
golang.org/x/term v0.21.0
23
22
)
Original file line number Diff line number Diff line change @@ -89,8 +89,6 @@ github.com/umlx5h/go-runewidth v0.0.0-20240106112317-9bbbb3702d5f h1:T8MNFeOIelX
89
89
github.com/umlx5h/go-runewidth v0.0.0-20240106112317-9bbbb3702d5f /go.mod h1:+aP7JKaGs4irGEvKbEMTjKb1uKLoRZKMrrUwdGzajsk =
90
90
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no =
91
91
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e /go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM =
92
- github.com/yookoala/realpath v1.0.0 h1:7OA9pj4FZd+oZDsyvXWQvjn5oBdcHRTV44PpdMSuImQ =
93
- github.com/yookoala/realpath v1.0.0 /go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE =
94
92
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY =
95
93
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 /go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI =
96
94
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M =
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import (
14
14
15
15
"github.com/moby/sys/mountinfo"
16
16
"github.com/umlx5h/gtrash/internal/env"
17
- "github.com/yookoala/realpath"
18
17
)
19
18
20
19
type trashDirType string
@@ -240,15 +239,15 @@ func getAllMountpoints() ([]string, error) {
240
239
}
241
240
242
241
var mountinfo_Mounted = mountinfo .Mounted
243
- var realpath_Realpath = realpath . Realpath
242
+ var EvalSymLinks = filepath . EvalSymlinks
244
243
245
244
// Obtain a mount point associated with a file.
246
245
// Same as df <PATH>
247
246
func getMountpoint (path string ) (string , error ) {
248
247
249
- // iterate over the parents of the real (without symlinks) path until we find a mount point
248
+ // iterate over the real (without symlinks) parents of path until we find a mount point
250
249
251
- candidate , err := realpath_Realpath ( path )
250
+ candidate , err := EvalSymLinks ( filepath . Dir ( path ) )
252
251
if err != nil {
253
252
return "" , err
254
253
}
@@ -266,7 +265,12 @@ func getMountpoint(path string) (string, error) {
266
265
return "" , errors .New ("mountpoint is '.'" )
267
266
}
268
267
269
- if mounted , err := mountinfo_Mounted (candidate ); err == nil && mounted {
268
+ mounted , err := mountinfo_Mounted (candidate )
269
+ if err != nil {
270
+ return "" , err
271
+ }
272
+
273
+ if mounted {
270
274
break
271
275
}
272
276
Original file line number Diff line number Diff line change @@ -20,7 +20,19 @@ func TestGetMountpoint(t *testing.T) {
20
20
return slices .Contains (mounts , fpath ), nil
21
21
}
22
22
23
- realpath_Realpath = func (path string ) (string , error ) {
23
+ // not evaluating each component here, just the entire path
24
+ symlinked := map [string ]string {
25
+ // file is a link
26
+ "/foo/link.txt" : "/foo/bar/target.txt" ,
27
+
28
+ // first component is a link
29
+ "/link" : "/foo/bar" ,
30
+ }
31
+
32
+ EvalSymLinks = func (path string ) (string , error ) {
33
+ if symlink , ok := symlinked [path ]; ok {
34
+ return symlink , nil
35
+ }
24
36
return path , nil
25
37
}
26
38
@@ -34,6 +46,9 @@ func TestGetMountpoint(t *testing.T) {
34
46
{path : "/ffoo/bar/a.txt" , want : "/ffoo/bar" },
35
47
{path : "/aaa/bbb/ccc/ddd.txt" , want : "/" },
36
48
{path : "/" , want : "/" },
49
+
50
+ {path : "/foo/link.txt" , want : "/foo" },
51
+ {path : "/link/a.txt" , want : "/foo/bar" },
37
52
}
38
53
39
54
t .Run ("normal" , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments