forked from TrueCloudLab/rclone
vfs: Add IsSymLink and TrimSymlink helpers
This commit is contained in:
parent
5c8bd27c7f
commit
0801342108
2 changed files with 23 additions and 0 deletions
|
@ -89,6 +89,13 @@ func (f *File) IsDir() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// IsSymlink returns true for symlinks when --links is enabled
|
||||
func (f *File) IsSymlink() bool {
|
||||
f.mu.RLock()
|
||||
defer f.mu.RUnlock()
|
||||
return f.d.vfs.IsSymlink(f.leaf)
|
||||
}
|
||||
|
||||
// Mode bits of the file or directory - satisfies Node interface
|
||||
func (f *File) Mode() (mode os.FileMode) {
|
||||
f.mu.RLock()
|
||||
|
|
16
vfs/vfs.go
16
vfs/vfs.go
|
@ -714,3 +714,19 @@ func (vfs *VFS) AddVirtual(remote string, size int64, isDir bool) error {
|
|||
dir.AddVirtual(leaf, size, false)
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsSymlink returns true if remote ends with fs.LinkSuffix when --links is enabled
|
||||
func (vfs *VFS) IsSymlink(remote string) bool {
|
||||
return vfs.Opt.Links && strings.HasSuffix(remote, fs.LinkSuffix)
|
||||
}
|
||||
|
||||
// TrimSymlink returns true if remote ends with fs.LinkSuffix when --links is enabled
|
||||
// Also, if it's a link, it's trimmed from its fs.LinkSuffix
|
||||
func (vfs *VFS) TrimSymlink(remote string) (string, bool) {
|
||||
if vfs.IsSymlink(remote) {
|
||||
remote := strings.TrimSuffix(remote, fs.LinkSuffix)
|
||||
return remote, true
|
||||
}
|
||||
|
||||
return remote, false
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue