MCPcopy
hub / github.com/syncthing/syncthing / removeFolder

Method removeFolder

lib/model/model.go:461–499  ·  view source on GitHub ↗
(cfg config.FolderConfiguration)

Source from the content-addressed store, hash-verified

459}
460
461func (m *model) removeFolder(cfg config.FolderConfiguration) {
462 slog.Info("Removing folder", cfg.LogAttr())
463 defer slog.Info("Removed folder", cfg.LogAttr())
464
465 m.mut.RLock()
466 wait := m.folderRunners.StopAndWaitChan(cfg.ID, 0)
467 m.mut.RUnlock()
468 <-wait
469
470 m.mut.Lock()
471
472 isPathUnique := true
473 for folderID, folderCfg := range m.folderCfgs {
474 if folderID != cfg.ID && folderCfg.Path == cfg.Path {
475 isPathUnique = false
476 break
477 }
478 }
479 if isPathUnique {
480 // Remove (if empty and removable) or move away (if non-empty or
481 // otherwise not removable) Syncthing-specific marker files.
482 if err := cfg.RemoveMarker(); err != nil && !errors.Is(err, os.ErrNotExist) {
483 moved := config.DefaultMarkerName + time.Now().Format(".removed-20060102-150405")
484 fs := cfg.Filesystem()
485 _ = fs.Rename(config.DefaultMarkerName, moved)
486 }
487 }
488
489 m.cleanupFolderLocked(cfg)
490 m.indexHandlers.Each(func(_ protocol.DeviceID, r *indexHandlerRegistry) error {
491 r.Remove(cfg.ID)
492 return nil
493 })
494
495 m.mut.Unlock()
496
497 // Remove it from the database
498 _ = m.sdb.DropFolder(cfg.ID)
499}
500
501// Need to hold lock on m.mut when calling this.
502func (m *model) cleanupFolderLocked(cfg config.FolderConfiguration) {

Callers 2

CommitConfigurationMethod · 0.95

Calls 12

cleanupFolderLockedMethod · 0.95
StopAndWaitChanMethod · 0.80
RemoveMarkerMethod · 0.80
FilesystemMethod · 0.80
EachMethod · 0.80
UnlockMethod · 0.80
NowMethod · 0.65
RenameMethod · 0.65
RemoveMethod · 0.65
DropFolderMethod · 0.65
LogAttrMethod · 0.45
IsMethod · 0.45

Tested by 1