From a557d62c4a5e5be7dee0d969a73e585864381b33 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sun, 25 Mar 2018 22:05:47 +0200 Subject: [PATCH] all: Transition to using fs watcher by default (fixes #4552) --- etc/linux-systemd/system/syncthing@.service | 1 - etc/linux-systemd/user/syncthing.service | 1 - gui/default/assets/lang/lang-en.json | 8 ++ gui/default/syncthing/core/notifications.html | 28 +++++ .../syncthing/core/syncthingController.js | 34 +++++- .../syncthing/folder/editFolderModalView.html | 112 ++++++++++-------- lib/config/config.go | 11 +- lib/config/config_test.go | 3 +- lib/config/folderconfiguration.go | 21 ++-- lib/config/testdata/v25.xml | 2 +- lib/config/testdata/v26.xml | 2 +- lib/config/testdata/v27.xml | 2 +- lib/config/testdata/v28.xml | 16 +++ 13 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 lib/config/testdata/v28.xml diff --git a/etc/linux-systemd/system/syncthing@.service b/etc/linux-systemd/system/syncthing@.service index 3928eee8b..1de4274ad 100644 --- a/etc/linux-systemd/system/syncthing@.service +++ b/etc/linux-systemd/system/syncthing@.service @@ -2,7 +2,6 @@ Description=Syncthing - Open Source Continuous File Synchronization for %I Documentation=man:syncthing(1) After=network.target -Wants=syncthing-inotify@.service [Service] User=%i diff --git a/etc/linux-systemd/user/syncthing.service b/etc/linux-systemd/user/syncthing.service index 692626a71..6a9f3b7af 100644 --- a/etc/linux-systemd/user/syncthing.service +++ b/etc/linux-systemd/user/syncthing.service @@ -1,7 +1,6 @@ [Unit] Description=Syncthing - Open Source Continuous File Synchronization Documentation=man:syncthing(1) -Wants=syncthing-inotify.service [Service] ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0 diff --git a/gui/default/assets/lang/lang-en.json b/gui/default/assets/lang/lang-en.json index dbf2944c5..5746f03d3 100644 --- a/gui/default/assets/lang/lang-en.json +++ b/gui/default/assets/lang/lang-en.json @@ -12,6 +12,7 @@ "Add Remote Device": "Add Remote Device", "Add devices from the introducer to our device list, for mutually shared folders.": "Add devices from the introducer to our device list, for mutually shared folders.", "Add new folder?": "Add new folder?", + "Additionally the full rescan interval will be increased (times 60, i.e. new default of 1h). You can also configure it manually for every folder later after choosing No.": "Additionally the full rescan interval will be increased (times 60, i.e. new default of 1h). You can also configure it manually for every folder later after choosing No.", "Address": "Address", "Addresses": "Addresses", "Advanced": "Advanced", @@ -49,6 +50,7 @@ "Connection Error": "Connection Error", "Connection Type": "Connection Type", "Connections": "Connections", + "Continuously watching for changes is now available within Syncthing. This will detect changes on disk and issue a scan on only the modified paths. The benefits are that changes are propagated quicker and that less full scans are required.": "Continuously watching for changes is now available within Syncthing. This will detect changes on disk and issue a scan on only the modified paths. The benefits are that changes are propagated quicker and that less full scans are required.", "Copied from elsewhere": "Copied from elsewhere", "Copied from original": "Copied from original", "Copyright © 2014-2016 the following Contributors:": "Copyright © 2014-2016 the following Contributors:", @@ -75,6 +77,7 @@ "Discovery Failures": "Discovery Failures", "Do not restore": "Do not restore", "Do not restore all": "Do not restore all", + "Do you want to enable watching for changes for all your folders?": "Do you want to enable watching for changes for all your folders?", "Documentation": "Documentation", "Download Rate": "Download Rate", "Downloaded": "Downloaded", @@ -114,6 +117,7 @@ "Folder Path": "Folder Path", "Folder Type": "Folder Type", "Folders": "Folders", + "Full Rescan Interval (s)": "Full Rescan Interval (s)", "GUI": "GUI", "GUI Authentication Password": "GUI Authentication Password", "GUI Authentication User": "GUI Authentication User", @@ -193,6 +197,7 @@ "Periodic scanning at given interval and disabled watching for changes": "Periodic scanning at given interval and disabled watching for changes", "Periodic scanning at given interval and enabled watching for changes": "Periodic scanning at given interval and enabled watching for changes", "Periodic scanning at given interval and failed setting up watching for changes, retrying every 1m:": "Periodic scanning at given interval and failed setting up watching for changes, retrying every 1m:", + "Permissions": "Permissions", "Please consult the release notes before performing a major upgrade.": "Please consult the release notes before performing a major upgrade.", "Please set a GUI Authentication User and Password in the Settings dialog.": "Please set a GUI Authentication User and Password in the Settings dialog.", "Please wait": "Please wait", @@ -328,6 +333,9 @@ "Warning, this path is a parent directory of an existing folder \"{%otherFolderLabel%}\" ({%otherFolder%}).": "Warning, this path is a parent directory of an existing folder \"{{otherFolderLabel}}\" ({{otherFolder}}).", "Warning, this path is a subdirectory of an existing folder \"{%otherFolder%}\".": "Warning, this path is a subdirectory of an existing folder \"{{otherFolder}}\".", "Warning, this path is a subdirectory of an existing folder \"{%otherFolderLabel%}\" ({%otherFolder%}).": "Warning, this path is a subdirectory of an existing folder \"{{otherFolderLabel}}\" ({{otherFolder}}).", + "Warning: If you are using an external watcher like {%syncthingInotify%}, you should make sure it is deactivated.": "Warning: If you are using an external watcher like {{syncthingInotify}}, you should make sure it is deactivated.", + "Watch for Changes": "Watch for Changes", + "Watching for Changes": "Watching for Changes", "When adding a new device, keep in mind that this device must be added on the other side too.": "When adding a new device, keep in mind that this device must be added on the other side too.", "When adding a new folder, keep in mind that the Folder ID is used to tie folders together between devices. They are case sensitive and must match exactly between all devices.": "When adding a new folder, keep in mind that the Folder ID is used to tie folders together between devices. They are case sensitive and must match exactly between all devices.", "Yes": "Yes", diff --git a/gui/default/syncthing/core/notifications.html b/gui/default/syncthing/core/notifications.html index 061a26e04..34b437a72 100644 --- a/gui/default/syncthing/core/notifications.html +++ b/gui/default/syncthing/core/notifications.html @@ -41,3 +41,31 @@ + + +
+
+

Watching for Changes

+
+
+

Continuously watching for changes is now available within Syncthing. This will detect changes on disk and issue a scan on only the modified paths. The benefits are that changes are propagated quicker and that less full scans are required.

+

 Learn more

+

+ Do you want to enable watching for changes for all your folders?
+ Additionally the full rescan interval will be increased (times 60, i.e. new default of 1h). You can also configure it manually for every folder later after choosing No. +

+

Warning: If you are using an external watcher like {%syncthingInotify%}, you should make sure it is deactivated.

+
+ +
+
diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index 3ee265ddf..29d60e665 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -53,6 +53,7 @@ angular.module('syncthing.core') $scope.globalChangeEvents = {}; $scope.metricRates = false; $scope.folderPathErrors = {}; + $scope.currentFolder = {}; resetRemoteNeed(); try { @@ -62,8 +63,9 @@ angular.module('syncthing.core') $scope.folderDefaults = { selectedDevices: {}, type: "readwrite", - rescanIntervalS: 60, + rescanIntervalS: 3600, fsWatcherDelayS: 10, + fsWatcherEnabled: true, minDiskFree: {value: 1, unit: "%"}, maxConflicts: 10, fsync: true, @@ -1504,6 +1506,14 @@ angular.module('syncthing.core') $scope.currentFolder.path = pathJoin($scope.config.options.defaultFolderPath, newvalue); }); + $scope.$watch('currentFolder.fsWatcherEnabled', function (newvalue) { + if (newvalue) { + $scope.currentFolder.rescanIntervalS = 3600; + } else { + $scope.currentFolder.rescanIntervalS = 60; + } + }); + $scope.loadFormIntoScope = function (form) { console.log('loadFormIntoScope',form.$name); switch (form.$name) { @@ -2126,6 +2136,28 @@ angular.module('syncthing.core') return false; }; + $scope.activateAllFsWatchers = function() { + var folders = $scope.folderList(); + + $.each(folders, function(i) { + if (folders[i].fsWatcherEnabled) { + return; + } + folders[i].fsWatcherEnabled = true; + if (folders[i].rescanIntervalS === 0) { + return; + } + // Delay full scans, but scan at least once per day + folders[i].rescanIntervalS *= 60; + if (folders[i].rescanIntervalS > 86400) { + folders[i].rescanIntervalS = 86400; + } + }); + + $scope.config.folders = folders; + $scope.saveConfig(); + }; + $scope.bumpFile = function (folder, file) { var url = urlbase + "/db/prio?folder=" + encodeURIComponent(folder) + "&file=" + encodeURIComponent(file); // In order to get the right view of data in the response. diff --git a/gui/default/syncthing/folder/editFolderModalView.html b/gui/default/syncthing/folder/editFolderModalView.html index 3e559bafa..5abc6eb18 100644 --- a/gui/default/syncthing/folder/editFolderModalView.html +++ b/gui/default/syncthing/folder/editFolderModalView.html @@ -133,26 +133,75 @@
Creating ignore patterns, overwriting an existing file at {%path%}.
-
-
-
-
- -

- The rescan interval must be a non-negative number of seconds. -

+
+
+ +   Help
+
+
+  Watch for Changes +
+
+
+ Full Rescan Interval (s) +
+ +
+
+

+ The rescan interval must be a non-negative number of seconds. +

+
-
-
-
-
-
+ + + +

Files are protected from changes made on other devices, but changes made on this device will be sent to the rest of the cluster.

+
+
+ + +
+
+
+
+
+
+
+ +
+
+ +
+
+

+ Enter a non-negative number (e.g., "2.35") and select a unit. Percentages are as part of the total disk size. +

+
+
+
+ Ignore +

File permission bits are ignored when looking for changes. Use on FAT file systems.

Enter a non-negative number (e.g., "2.35") and select a unit. Percentages are as part of the total disk size. @@ -160,43 +209,6 @@

-
- -
-
- -   Help - -

Files are protected from changes made on other devices, but changes made on this device will be sent to the rest of the cluster.

-
-
-
- -
-

File permission bits are ignored when looking for changes. Use on FAT file systems.

-
-
- - -
-
- - -
-
-
diff --git a/lib/config/config.go b/lib/config/config.go index 9988f01f9..a72c361c8 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -32,7 +32,7 @@ import ( const ( OldestHandledVersion = 10 - CurrentVersion = 27 + CurrentVersion = 28 MaxRescanIntervalS = 365 * 24 * 60 * 60 ) @@ -315,6 +315,9 @@ func (cfg *Configuration) clean() error { if cfg.Version == 26 { convertV26V27(cfg) } + if cfg.Version == 27 { + convertV27V28(cfg) + } // Build a list of available devices existingDevices := make(map[protocol.DeviceID]bool) @@ -374,6 +377,12 @@ func (cfg *Configuration) clean() error { return nil } +func convertV27V28(cfg *Configuration) { + // Show a notification about enabling filesystem watching + cfg.Options.UnackedNotificationIDs = append(cfg.Options.UnackedNotificationIDs, "fsWatcherNotification") + cfg.Version = 28 +} + func convertV26V27(cfg *Configuration) { for i := range cfg.Folders { f := &cfg.Folders[i] diff --git a/lib/config/config_test.go b/lib/config/config_test.go index 73cebd702..0cf74bb21 100644 --- a/lib/config/config_test.go +++ b/lib/config/config_test.go @@ -206,7 +206,8 @@ func TestOverriddenValues(t *testing.T) { OverwriteRemoteDevNames: true, TempIndexMinBlocks: 100, UnackedNotificationIDs: []string{ - "channelNotification", // added in 17->18 migration + "channelNotification", // added in 17->18 migration + "fsWatcherNotification", // added in 27->28 migration }, WeakHashSelectionMethod: WeakHashNever, DefaultFolderPath: "/media/syncthing", diff --git a/lib/config/folderconfiguration.go b/lib/config/folderconfiguration.go index bb38650ce..4300691a3 100644 --- a/lib/config/folderconfiguration.go +++ b/lib/config/folderconfiguration.go @@ -67,16 +67,17 @@ type FolderDeviceConfiguration struct { func NewFolderConfiguration(myID protocol.DeviceID, id, label string, fsType fs.FilesystemType, path string) FolderConfiguration { f := FolderConfiguration{ - ID: id, - Label: label, - RescanIntervalS: 60, - FSWatcherDelayS: 10, - MinDiskFree: Size{Value: 1, Unit: "%"}, - Devices: []FolderDeviceConfiguration{{DeviceID: myID}}, - AutoNormalize: true, - MaxConflicts: -1, - FilesystemType: fsType, - Path: path, + ID: id, + Label: label, + RescanIntervalS: 3600, + FSWatcherEnabled: true, + FSWatcherDelayS: 10, + MinDiskFree: Size{Value: 1, Unit: "%"}, + Devices: []FolderDeviceConfiguration{{DeviceID: myID}}, + AutoNormalize: true, + MaxConflicts: -1, + FilesystemType: fsType, + Path: path, } f.prepare() return f diff --git a/lib/config/testdata/v25.xml b/lib/config/testdata/v25.xml index f5e0551c7..9c47f99e8 100644 --- a/lib/config/testdata/v25.xml +++ b/lib/config/testdata/v25.xml @@ -1,5 +1,5 @@ - + basic diff --git a/lib/config/testdata/v26.xml b/lib/config/testdata/v26.xml index 84121e9f2..4aae7bfd3 100644 --- a/lib/config/testdata/v26.xml +++ b/lib/config/testdata/v26.xml @@ -1,5 +1,5 @@ - + basic diff --git a/lib/config/testdata/v27.xml b/lib/config/testdata/v27.xml index c11d5e8bf..643cb7c5d 100644 --- a/lib/config/testdata/v27.xml +++ b/lib/config/testdata/v27.xml @@ -1,5 +1,5 @@ - + basic diff --git a/lib/config/testdata/v28.xml b/lib/config/testdata/v28.xml new file mode 100644 index 000000000..231cd882c --- /dev/null +++ b/lib/config/testdata/v28.xml @@ -0,0 +1,16 @@ + + + basic + + + 1 + -1 + true + + +
tcp://a
+
+ +
tcp://b
+
+