MCPcopy Index your code
hub / github.com/syncthing/syncthing / newBasicFilesystem

Function newBasicFilesystem

lib/fs/basicfs.go:68–113  ·  view source on GitHub ↗
(root string, opts ...Option)

Source from the content-addressed store, hash-verified

66}
67
68func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
69 if root == "" {
70 root = "." // Otherwise "" becomes "/" below
71 }
72
73 // The reason it's done like this:
74 // C: -> C:\ -> C:\ (issue that this is trying to fix)
75 // C:\somedir -> C:\somedir\ -> C:\somedir
76 // C:\somedir\ -> C:\somedir\ -> C:\somedir
77 // This way in the tests, we get away without OS specific separators
78 // in the test configs.
79 sep := string(filepath.Separator)
80 root = filepath.Clean(filepath.Dir(root + sep))
81
82 // Attempt tilde expansion; leave unchanged in case of error
83 if path, err := ExpandTilde(root); err == nil {
84 root = path
85 }
86
87 // Attempt absolutification; leave unchanged in case of error
88 if !filepath.IsAbs(root) {
89 // Abs() looks like a fairly expensive syscall on Windows, while
90 // IsAbs() is a whole bunch of string mangling. I think IsAbs() may be
91 // somewhat faster in the general case, hence the outer if...
92 if path, err := filepath.Abs(root); err == nil {
93 root = path
94 }
95 }
96
97 // Attempt to enable long filename support on Windows. We may still not
98 // have an absolute path here if the previous steps failed.
99 if build.IsWindows {
100 root = longFilenameSupport(root)
101 }
102
103 fs := &BasicFilesystem{
104 root: root,
105 options: opts,
106 userCache: newValueCache(time.Hour, user.LookupId),
107 groupCache: newValueCache(time.Hour, user.LookupGroupId),
108 }
109 for _, opt := range opts {
110 opt.apply(fs)
111 }
112 return fs
113}
114
115// rooted expands the relative path to the full path that is then used with os
116// package. If the relative path somehow causes the final path to escape the root

Callers 12

initFunction · 0.85
TestFakeFSCaseSensitiveFunction · 0.85
setupFunction · 0.85
TestNewBasicFilesystemFunction · 0.85
TestWatchWinRootFunction · 0.85
expectErrorForPathFunction · 0.85
TestWatchSubpathFunction · 0.85
TestUnrootedCheckedFunction · 0.85
TestWindowsPathsFunction · 0.85
TestResolveWindows83Function · 0.85
TestIsWindows83Function · 0.85

Calls 5

ExpandTildeFunction · 0.85
longFilenameSupportFunction · 0.85
newValueCacheFunction · 0.85
CleanMethod · 0.65
applyMethod · 0.65

Tested by 11

TestFakeFSCaseSensitiveFunction · 0.68
setupFunction · 0.68
TestNewBasicFilesystemFunction · 0.68
TestWatchWinRootFunction · 0.68
expectErrorForPathFunction · 0.68
TestWatchSubpathFunction · 0.68
TestUnrootedCheckedFunction · 0.68
TestWindowsPathsFunction · 0.68
TestResolveWindows83Function · 0.68
TestIsWindows83Function · 0.68