Merge pull request #1311 from krozycki/master

Button to rescan all folders (fixes #1151)
This commit is contained in:
Jakob Borg 2015-02-13 08:36:17 +01:00
commit 5d9396334c
5 changed files with 31 additions and 11 deletions

View File

@ -652,11 +652,19 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
func restPostScan(m *model.Model, w http.ResponseWriter, r *http.Request) { func restPostScan(m *model.Model, w http.ResponseWriter, r *http.Request) {
qs := r.URL.Query() qs := r.URL.Query()
folder := qs.Get("folder") folder := qs.Get("folder")
if folder != "" {
sub := qs.Get("sub") sub := qs.Get("sub")
err := m.ScanFolderSub(folder, sub) err := m.ScanFolderSub(folder, sub)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) 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)
}
}
} }
func restPostBump(m *model.Model, w http.ResponseWriter, r *http.Request) { func restPostBump(m *model.Model, w http.ResponseWriter, r *http.Request) {

View File

@ -273,10 +273,11 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <span class="pull-right">
<button class="btn btn-sm btn-default pull-right" ng-click="addFolder()"><span class="glyphicon glyphicon-plus"></span>&emsp;<span translate>Add Folder</span></button> <button class="btn btn-sm btn-default" ng-click="rescanAllFolders()"><span class="glyphicon glyphicon-repeat"></span>&emsp;<span translate>Rescan All</span></button>
<button class="btn btn-sm btn-default" ng-click="addFolder()"><span class="glyphicon glyphicon-plus"></span>&emsp;<span translate>Add Folder</span></button>
</span>
<div class="clearfix"></div> <div class="clearfix"></div>
</div>
<hr class="visible-sm"/> <hr class="visible-sm"/>
</div> </div>

View File

@ -1156,6 +1156,10 @@ angular.module('syncthing.core')
$scope.reportPreview = true; $scope.reportPreview = true;
}; };
$scope.rescanAllFolders = function () {
$http.post(urlbase + "/scan");
};
$scope.rescanFolder = function (folder) { $scope.rescanFolder = function (folder) {
$http.post(urlbase + "/scan?folder=" + encodeURIComponent(folder)); $http.post(urlbase + "/scan?folder=" + encodeURIComponent(folder));
}; };

File diff suppressed because one or more lines are too long

View File

@ -1111,7 +1111,7 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) {
m.fmut.Unlock() m.fmut.Unlock()
} }
func (m *Model) ScanFolders() { func (m *Model) ScanFolders() map[string]error {
m.fmut.RLock() m.fmut.RLock()
var folders = make([]string, 0, len(m.folderCfgs)) var folders = make([]string, 0, len(m.folderCfgs))
for folder := range m.folderCfgs { for folder := range m.folderCfgs {
@ -1119,6 +1119,9 @@ func (m *Model) ScanFolders() {
} }
m.fmut.RUnlock() m.fmut.RUnlock()
var errors = make(map[string]error, len(m.folderCfgs))
var errorsMut sync.Mutex
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(len(folders)) wg.Add(len(folders))
for _, folder := range folders { for _, folder := range folders {
@ -1126,12 +1129,16 @@ func (m *Model) ScanFolders() {
go func() { go func() {
err := m.ScanFolder(folder) err := m.ScanFolder(folder)
if err != nil { if err != nil {
errorsMut.Lock()
errors[folder] = err
errorsMut.Unlock()
m.cfg.InvalidateFolder(folder, err.Error()) m.cfg.InvalidateFolder(folder, err.Error())
} }
wg.Done() wg.Done()
}() }()
} }
wg.Wait() wg.Wait()
return errors
} }
func (m *Model) ScanFolder(folder string) error { func (m *Model) ScanFolder(folder string) error {