mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07:00
Button to rescan all folders, fixes #1151
This commit is contained in:
parent
bbaeca96eb
commit
ec160f1f0a
@ -652,10 +652,18 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||
func restPostScan(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
||||
qs := r.URL.Query()
|
||||
folder := qs.Get("folder")
|
||||
sub := qs.Get("sub")
|
||||
err := m.ScanFolderSub(folder, sub)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
if folder != "" {
|
||||
sub := qs.Get("sub")
|
||||
err := m.ScanFolderSub(folder, sub)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
}
|
||||
} else {
|
||||
errors := m.ScanFolders()
|
||||
if len(errors) > 0 {
|
||||
http.Error(w, "Error scanning folders", 500)
|
||||
json.NewEncoder(w).Encode(errors)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,10 +273,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-sm btn-default pull-right" ng-click="addFolder()"><span class="glyphicon glyphicon-plus"></span> <span translate>Add Folder</span></button>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<span class="pull-right">
|
||||
<button class="btn btn-sm btn-default" ng-click="rescanAllFolders()"><span class="glyphicon glyphicon-repeat"></span> <span translate>Rescan All</span></button>
|
||||
<button class="btn btn-sm btn-default" ng-click="addFolder()"><span class="glyphicon glyphicon-plus"></span> <span translate>Add Folder</span></button>
|
||||
</span>
|
||||
<div class="clearfix"></div>
|
||||
<hr class="visible-sm"/>
|
||||
</div>
|
||||
|
||||
|
@ -1156,6 +1156,10 @@ angular.module('syncthing.core')
|
||||
$scope.reportPreview = true;
|
||||
};
|
||||
|
||||
$scope.rescanAllFolders = function () {
|
||||
$http.post(urlbase + "/scan");
|
||||
};
|
||||
|
||||
$scope.rescanFolder = function (folder) {
|
||||
$http.post(urlbase + "/scan?folder=" + encodeURIComponent(folder));
|
||||
};
|
||||
|
File diff suppressed because one or more lines are too long
@ -1111,7 +1111,7 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) {
|
||||
m.fmut.Unlock()
|
||||
}
|
||||
|
||||
func (m *Model) ScanFolders() {
|
||||
func (m *Model) ScanFolders() map[string]error {
|
||||
m.fmut.RLock()
|
||||
var folders = make([]string, 0, len(m.folderCfgs))
|
||||
for folder := range m.folderCfgs {
|
||||
@ -1119,6 +1119,9 @@ func (m *Model) ScanFolders() {
|
||||
}
|
||||
m.fmut.RUnlock()
|
||||
|
||||
var errors = make(map[string]error, len(m.folderCfgs))
|
||||
var errorsMut sync.Mutex
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(folders))
|
||||
for _, folder := range folders {
|
||||
@ -1126,12 +1129,16 @@ func (m *Model) ScanFolders() {
|
||||
go func() {
|
||||
err := m.ScanFolder(folder)
|
||||
if err != nil {
|
||||
errorsMut.Lock()
|
||||
errors[folder] = err
|
||||
errorsMut.Unlock()
|
||||
m.cfg.InvalidateFolder(folder, err.Error())
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
return errors
|
||||
}
|
||||
|
||||
func (m *Model) ScanFolder(folder string) error {
|
||||
|
Loading…
Reference in New Issue
Block a user