MCPcopy Index your code
hub / github.com/devspace-sh/devspace / NewSymlink

Function NewSymlink

pkg/devspace/sync/symlink.go:39–72  ·  view source on GitHub ↗

NewSymlink creates a new symlink object

(upstream *upstream, symlinkPath, targetPath string, isDir bool, ignoreMatcher ignoreparser.IgnoreParser)

Source from the content-addressed store, hash-verified

37
38// NewSymlink creates a new symlink object
39func NewSymlink(upstream *upstream, symlinkPath, targetPath string, isDir bool, ignoreMatcher ignoreparser.IgnoreParser) (*Symlink, error) {
40 symlink := &Symlink{
41 SymlinkPath: symlinkPath,
42 TargetPath: targetPath,
43 IsDir: isDir,
44 events: make(chan notify.EventInfo, 1000),
45 upstream: upstream,
46 }
47
48 symlink.watcher = notify.NewTree()
49 _ = symlink.watcher.Watch(targetPath, symlink.events, func(path string) bool {
50 if ignoreMatcher == nil || ignoreMatcher.RequireFullScan() {
51 return false
52 }
53
54 stat, err := os.Stat(path)
55 if err != nil {
56 return false
57 }
58
59 return ignoreMatcher.Matches(path[len(symlink.SymlinkPath):], stat.IsDir())
60 }, notify.All)
61
62 go func() {
63 for event := range symlink.events {
64 symlink.upstream.events <- &symlinkEvent{
65 path: symlink.rewritePath(event.Path()),
66 event: event.Event(),
67 }
68 }
69 }()
70
71 return symlink, nil
72}
73
74func (s *Symlink) rewritePath(path string) string {
75 return s.SymlinkPath + path[len(s.TargetPath):]

Callers 1

AddSymlinkMethod · 0.85

Calls 7

rewritePathMethod · 0.95
WatchMethod · 0.80
RequireFullScanMethod · 0.65
MatchesMethod · 0.65
PathMethod · 0.65
IsDirMethod · 0.45
EventMethod · 0.45

Tested by

no test coverage detected