File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import (
2929 "syscall"
3030 "time"
3131
32+ "github.com/gofrs/flock"
3233 "github.com/syncthing/syncthing/lib/build"
3334 "github.com/syncthing/syncthing/lib/config"
3435 "github.com/syncthing/syncthing/lib/events"
@@ -63,6 +64,7 @@ type Client struct {
6364 extraneousIgnored []string
6465 Measurements * Measurements
6566 logHandler * logHandler
67+ appLock * flock.Flock
6668}
6769
6870type Change struct {
@@ -598,6 +600,16 @@ func (clt *Client) Load(resetDeltaIdxs bool) error {
598600 }
599601 clt .config = config
600602
603+ // Check if we are the only instance running
604+ clt .appLock = flock .New (locations .Get (locations .LockFile ))
605+ slog .Info ("Attempting to obtain application lock at" , "path" , locations .Get (locations .LockFile ))
606+ locked , err := clt .appLock .TryLock ()
607+ if err != nil {
608+ return fmt .Errorf ("failed to obtain lock: %w" , err )
609+ } else if ! locked {
610+ return fmt .Errorf ("The app cannot be started, as it appears it is already running. If this error persists, try restarting your device." )
611+ }
612+
601613 // Default retention interval taken from Syncthing's CLI default
602614 dbDeleteRetentionInterval := time .Duration (4320 ) * time .Hour
603615 // It really wants to set up a temporary API while migrating...
You can’t perform that action at this time.
0 commit comments