Skip to content

Commit

Permalink
add missing mutex protection
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Sep 23, 2024
1 parent 340e763 commit 53b32d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/model/folder_virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ func (f *virtualFolderSyncthingService) Serve(ctx context.Context) error {

if f.mountService == nil {
stVF := &syncthingVirtualFolderFuseAdapter{
vFSS: f,
folderID: f.ID,
model: f.model,
fset: f.fset,
ino_mu: sync.NewMutex(),
next_ino_nr: 1,
ino_mapping: make(map[string]uint64),
directories: make(map[string]*TreeEntry),
vFSS: f,
folderID: f.ID,
model: f.model,
fset: f.fset,
ino_mu: sync.NewMutex(),
next_ino_nr: 1,
ino_mapping: make(map[string]uint64),
directories_mu: sync.NewMutex(),
directories: make(map[string]*TreeEntry),
}
mount, err := NewVirtualFolderMount(f.mountPath, f.ID, f.Label, stVF)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions lib/model/folder_virtual_access_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type syncthingVirtualFolderFuseAdapter struct {
next_ino_nr uint64
ino_mapping map[string]uint64

// encoded directories
directories map[string]*TreeEntry
// encrypted directories
directories_mu sync.Mutex
directories map[string]*TreeEntry
}

var _ = (SyncthingVirtualFolderAccessI)((*syncthingVirtualFolderFuseAdapter)(nil))
Expand Down Expand Up @@ -65,6 +66,8 @@ func (stf *syncthingVirtualFolderFuseAdapter) lookupFile(path string) (info *db.
fi, ok := snap.GetGlobalTruncated(path)
if !ok {
if stf.vFSS.Type.IsReceiveEncrypted() {
stf.directories_mu.Lock()
defer stf.directories_mu.Unlock()
logger.DefaultLogger.Infof("ENC VIRT lookup %s - %+v", path, stf.directories)
entry, exists := stf.directories[path]
if exists {
Expand Down Expand Up @@ -459,7 +462,9 @@ func (f *syncthingVirtualFolderFuseAdapter) readDir(path string) (stream ffs.Dir
Name: parts[0],
Type: protocol.FileInfoTypeDirectory,
}
f.directories_mu.Lock()
f.directories[path+parts[0]] = entry
f.directories_mu.Unlock()
fileMap[parts[0]] = entry
}
}
Expand Down

0 comments on commit 53b32d9

Please sign in to comment.