forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlink.go
67 lines (55 loc) · 1.92 KB
/
symlink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libfuse
import (
"os"
"syscall"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
// Symlink represents KBFS symlinks.
type Symlink struct {
// The directory this symlink is in. This should be safe to store
// here, without fear of Renames etc making it stale, because we
// never persist a Symlink into Folder.nodes; it has no
// libkbfs.Node, so that's impossible. This should make FUSE
// Lookup etc always get new nodes, limiting the lifetime of a
// single Symlink value.
parent *Dir
name string
inode uint64
}
var _ fs.Node = (*Symlink)(nil)
// Attr implements the fs.Node interface for Symlink
func (s *Symlink) Attr(ctx context.Context, a *fuse.Attr) (err error) {
s.parent.folder.fs.log.CDebugf(ctx, "Symlink Attr")
defer func() { err = s.parent.folder.processError(ctx, libkbfs.ReadMode, err) }()
_, de, err := s.parent.folder.fs.config.KBFSOps().Lookup(ctx, s.parent.node, s.name)
if err != nil {
if _, ok := err.(libkbfs.NoSuchNameError); ok {
return fuse.ESTALE
}
return err
}
s.parent.folder.fillAttrWithUIDAndWritePerm(ctx, s.parent.node, &de, a)
a.Mode = os.ModeSymlink | a.Mode | 0500
a.Inode = s.inode
return nil
}
var _ fs.NodeReadlinker = (*Symlink)(nil)
// Readlink implements the fs.NodeReadlinker interface for Symlink
func (s *Symlink) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (link string, err error) {
s.parent.folder.fs.log.CDebugf(ctx, "Symlink Readlink")
defer func() { err = s.parent.folder.processError(ctx, libkbfs.ReadMode, err) }()
_, de, err := s.parent.folder.fs.config.KBFSOps().Lookup(ctx, s.parent.node, s.name)
if err != nil {
return "", err
}
if de.Type != libkbfs.Sym {
return "", fuse.Errno(syscall.EINVAL)
}
return de.SymPath, nil
}