MCPcopy Create free account
hub / github.com/coder/envbuilder / libraryDirectorySymlinks

Function libraryDirectorySymlinks

internal/ebutil/libs.go:42–74  ·  view source on GitHub ↗

libraryDirectorySymlinks returns a mapping of each library (basename) with a list of their symlinks (basename). Libraries with no symlinks do not appear in the mapping.

(m mounter, libDir string)

Source from the content-addressed store, hash-verified

40// list of their symlinks (basename). Libraries with no symlinks do not appear
41// in the mapping.
42func libraryDirectorySymlinks(m mounter, libDir string) (map[string][]string, error) {
43 des, err := m.ReadDir(libDir)
44 if err != nil {
45 return nil, fmt.Errorf("read directory %s: %w", libDir, err)
46 }
47
48 libsSymlinks := make(map[string][]string)
49 for _, de := range des {
50 if de.IsDir() {
51 continue
52 }
53
54 if de.Type()&os.ModeSymlink != os.ModeSymlink {
55 // Not a symlink. Skip.
56 continue
57 }
58
59 symlink := filepath.Join(libDir, de.Name())
60 path, err := m.EvalSymlinks(symlink)
61 if err != nil {
62 return nil, fmt.Errorf("eval symlink %s: %w", symlink, err)
63 }
64
65 path = filepath.Base(path)
66 if _, ok := libsSymlinks[path]; !ok {
67 libsSymlinks[path] = make([]string, 0, 1)
68 }
69
70 libsSymlinks[path] = append(libsSymlinks[path], de.Name())
71 }
72
73 return libsSymlinks, nil
74}
75
76// moveLibSymlinks moves a list of symlinks from source to destination directory.
77func moveLibSymlinks(m mounter, symlinks []string, srcDir, destDir string) error {

Callers 1

tempRemountFunction · 0.85

Calls 6

TypeMethod · 0.80
JoinMethod · 0.80
ReadDirMethod · 0.65
EvalSymlinksMethod · 0.65
IsDirMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected