Skip to content

Commit

Permalink
gui, lib/config, lib/model: Add ability to ignore folders offered by …
Browse files Browse the repository at this point in the history
…other nodes (fixes syncthing#3993)

GitHub-Pull-Request: syncthing#4179
LGTM: AudriusButkevicius, calmh
  • Loading branch information
nrm21 authored and calmh committed May 31, 2017
1 parent 3959eb2 commit b49bbe8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gui/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ <h3 class="panel-title">
<button type="button" class="btn btn-sm btn-default" ng-click="dismissFolderRejection(event.data.folder, event.data.device)">
<span class="fa fa-clock-o"></span>&nbsp;<span translate>Later</span>
</button>
<button type="button" class="btn btn-sm btn-default" ng-click="ignoreRejectedFolder(event.data.folder, event.data.device)">
<span class="fa fa-times"></span>&nbsp;<span translate>Ignore</span>
</button>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions gui/default/syncthing/core/syncthingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,12 @@ angular.module('syncthing.core')
delete $scope.folderRejections[folder + "-" + device];
};

$scope.ignoreRejectedFolder = function (folder, device) {
$scope.config.ignoredFolders.push(folder);
$scope.saveConfig();
$scope.dismissFolderRejection(folder, device);
};

$scope.sharesFolder = function (folderCfg) {
var names = [];
folderCfg.devices.forEach(function (device) {
Expand Down
8 changes: 8 additions & 0 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type Configuration struct {
GUI GUIConfiguration `xml:"gui" json:"gui"`
Options OptionsConfiguration `xml:"options" json:"options"`
IgnoredDevices []protocol.DeviceID `xml:"ignoredDevice" json:"ignoredDevices"`
IgnoredFolders []string `xml:"ignoredFolder" json:"ignoredFolders"`
XMLName xml.Name `xml:"configuration" json:"-"`

MyID protocol.DeviceID `xml:"-" json:"-"` // Provided by the instantiator.
Expand Down Expand Up @@ -182,6 +183,10 @@ func (cfg Configuration) Copy() Configuration {
newCfg.IgnoredDevices = make([]protocol.DeviceID, len(cfg.IgnoredDevices))
copy(newCfg.IgnoredDevices, cfg.IgnoredDevices)

// FolderConfiguraion.ID is type string
newCfg.IgnoredFolders = make([]string, len(cfg.IgnoredFolders))
copy(newCfg.IgnoredFolders, cfg.IgnoredFolders)

return newCfg
}

Expand Down Expand Up @@ -238,6 +243,9 @@ func (cfg *Configuration) clean() error {
if cfg.IgnoredDevices == nil {
cfg.IgnoredDevices = []protocol.DeviceID{}
}
if cfg.IgnoredFolders == nil {
cfg.IgnoredFolders = []string{}
}
if cfg.Options.AlwaysLocalNets == nil {
cfg.Options.AlwaysLocalNets = []string{}
}
Expand Down
13 changes: 13 additions & 0 deletions lib/config/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ func (w *Wrapper) IgnoredDevice(id protocol.DeviceID) bool {
return false
}

// IgnoredFolder returns whether or not share attempts for the given
// folder should be silently ignored.
func (w *Wrapper) IgnoredFolder(folder string) bool {
w.mut.Lock()
defer w.mut.Unlock()
for _, nfolder := range w.cfg.IgnoredFolders {
if folder == nfolder {
return true
}
}
return false
}

// Device returns the configuration for the given device and an "ok" bool.
func (w *Wrapper) Device(id protocol.DeviceID) (DeviceConfiguration, bool) {
w.mut.Lock()
Expand Down
5 changes: 5 additions & 0 deletions lib/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,11 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
continue
}

if m.cfg.IgnoredFolder(folder.ID) {
l.Infof("Ignoring folder %s from device %s since we are configured to", folder.Description(), deviceID)
continue
}

if !m.folderSharedWithLocked(folder.ID, deviceID) {
events.Default.Log(events.FolderRejected, map[string]string{
"folder": folder.ID,
Expand Down
1 change: 1 addition & 0 deletions man/syncthing-rest-api.7
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Returns the current configuration.
"tempIndexMinBlocks": 10
},
"ignoredDevices": []
"ignoredFolders": []
}
}
.ft P
Expand Down

0 comments on commit b49bbe8

Please sign in to comment.