MCPcopy
hub / github.com/syncthing/syncthing / CreateMarker

Method CreateMarker

lib/config/folderconfiguration.go:157–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155}
156
157func (f *FolderConfiguration) CreateMarker() error {
158 if err := f.CheckPath(); !errors.Is(err, ErrMarkerMissing) {
159 return err
160 }
161 if f.MarkerName != DefaultMarkerName {
162 // Folder uses a non-default marker so we shouldn't mess with it.
163 // Pretend we created it and let the subsequent health checks sort
164 // out the actual situation.
165 return nil
166 }
167
168 ffs := f.Filesystem()
169
170 // Create the marker as a directory
171 err := ffs.Mkdir(DefaultMarkerName, 0o755)
172 if err != nil {
173 return err
174 }
175
176 // Create a file inside it, reducing the risk of the marker directory
177 // being removed by automated cleanup tools.
178 markerFile := filepath.Join(DefaultMarkerName, f.markerFilename())
179 if err := fs.WriteFile(ffs, markerFile, f.markerContents(), 0o644); err != nil {
180 return err
181 }
182
183 // Sync & hide the containing directory
184 if dir, err := ffs.Open("."); err != nil {
185 l.Debugln("folder marker: open . failed:", err)
186 } else if err := dir.Sync(); err != nil {
187 l.Debugln("folder marker: fsync . failed:", err)
188 }
189 ffs.Hide(DefaultMarkerName)
190
191 return nil
192}
193
194func (f *FolderConfiguration) RemoveMarker() error {
195 ffs := f.Filesystem()

Callers 1

Calls 11

CheckPathMethod · 0.95
FilesystemMethod · 0.95
markerFilenameMethod · 0.95
markerContentsMethod · 0.95
WriteFileFunction · 0.92
DebuglnMethod · 0.80
MkdirMethod · 0.65
OpenMethod · 0.65
SyncMethod · 0.65
HideMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected