mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-12 16:26:37 +00:00
Fix and relax locking
This commit is contained in:
parent
3daa26e1f7
commit
76900ae291
@ -733,14 +733,13 @@ func (m *Model) ConnectedTo(deviceID protocol.DeviceID) bool {
|
|||||||
func (m *Model) GetIgnores(folder string) ([]string, error) {
|
func (m *Model) GetIgnores(folder string) ([]string, error) {
|
||||||
var lines []string
|
var lines []string
|
||||||
|
|
||||||
|
m.fmut.RLock()
|
||||||
cfg, ok := m.folderCfgs[folder]
|
cfg, ok := m.folderCfgs[folder]
|
||||||
|
m.fmut.RUnlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
return lines, fmt.Errorf("Folder %s does not exist", folder)
|
return lines, fmt.Errorf("Folder %s does not exist", folder)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.fmut.Lock()
|
|
||||||
defer m.fmut.Unlock()
|
|
||||||
|
|
||||||
fd, err := os.Open(filepath.Join(cfg.Path, ".stignore"))
|
fd, err := os.Open(filepath.Join(cfg.Path, ".stignore"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@ -1239,10 +1238,9 @@ func (m *Model) Override(folder string) {
|
|||||||
// This is guaranteed to increment if the contents of the local folder has
|
// This is guaranteed to increment if the contents of the local folder has
|
||||||
// changed.
|
// changed.
|
||||||
func (m *Model) CurrentLocalVersion(folder string) uint64 {
|
func (m *Model) CurrentLocalVersion(folder string) uint64 {
|
||||||
m.fmut.Lock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.Unlock()
|
|
||||||
|
|
||||||
fs, ok := m.folderFiles[folder]
|
fs, ok := m.folderFiles[folder]
|
||||||
|
m.fmut.RUnlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
// The folder might not exist, since this can be called with a user
|
// The folder might not exist, since this can be called with a user
|
||||||
// specified folder name from the REST interface.
|
// specified folder name from the REST interface.
|
||||||
@ -1256,8 +1254,8 @@ func (m *Model) CurrentLocalVersion(folder string) uint64 {
|
|||||||
// sent by remote peers. This is guaranteed to increment if the contents of
|
// sent by remote peers. This is guaranteed to increment if the contents of
|
||||||
// the remote or global folder has changed.
|
// the remote or global folder has changed.
|
||||||
func (m *Model) RemoteLocalVersion(folder string) uint64 {
|
func (m *Model) RemoteLocalVersion(folder string) uint64 {
|
||||||
m.fmut.Lock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.Unlock()
|
defer m.fmut.RUnlock()
|
||||||
|
|
||||||
fs, ok := m.folderFiles[folder]
|
fs, ok := m.folderFiles[folder]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -1275,10 +1273,9 @@ func (m *Model) RemoteLocalVersion(folder string) uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) availability(folder string, file string) []protocol.DeviceID {
|
func (m *Model) availability(folder string, file string) []protocol.DeviceID {
|
||||||
m.fmut.Lock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.Unlock()
|
|
||||||
|
|
||||||
fs, ok := m.folderFiles[folder]
|
fs, ok := m.folderFiles[folder]
|
||||||
|
m.fmut.RUnlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user