Browse Source

Hard override on changes from master repo

Jakob Borg 11 years ago
parent
commit
26ebbee877
5 changed files with 40 additions and 1 deletions
  1. 0 0
      auto/gui.files.go
  2. 7 0
      cmd/syncthing/gui.go
  3. 6 0
      gui/app.js
  4. 4 1
      gui/index.html
  5. 23 0
      model/model.go

File diff suppressed because it is too large
+ 0 - 0
auto/gui.files.go


+ 7 - 0
cmd/syncthing/gui.go

@@ -108,6 +108,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro
 	router.Post("/rest/error", restPostError)
 	router.Post("/rest/error/clear", restClearErrors)
 	router.Post("/rest/discovery/hint", restPostDiscoveryHint)
+	router.Post("/rest/model/override", restPostOverride)
 
 	mr := martini.New()
 	mr.Use(csrfMiddleware)
@@ -172,6 +173,12 @@ func restGetModel(m *model.Model, w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(res)
 }
 
+func restPostOverride(m *model.Model, r *http.Request) {
+	var qs = r.URL.Query()
+	var repo = qs.Get("repo")
+	m.Override(repo)
+}
+
 func restGetNeed(m *model.Model, w http.ResponseWriter, r *http.Request) {
 	var qs = r.URL.Query()
 	var repo = qs.Get("repo")

+ 6 - 0
gui/app.js

@@ -627,6 +627,12 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
         }
     };
 
+    $scope.override = function (repo) {
+        $http.post(urlbase + "/model/override?repo=" + encodeURIComponent(repo)).success(function () {
+            $scope.refresh();
+        });
+    };
+
     $scope.init();
     setInterval($scope.refresh, 10000);
 });

+ 4 - 1
gui/index.html

@@ -206,7 +206,10 @@ found in the LICENSE file.
                     </tbody>
                   </table>
                 </div>
-                <span class="pull-right"><a class="btn btn-sm btn-primary" href="" ng-click="editRepo(repo)"><span class="glyphicon glyphicon-pencil"></span>&emsp;Edit</a></span>
+                <span class="pull-right">
+                  <a class="btn btn-sm btn-primary" href="" ng-click="editRepo(repo)"><span class="glyphicon glyphicon-pencil"></span>&emsp;Edit</a>
+                  <a class="btn btn-sm btn-danger" ng-if="repo.ReadOnly && model[repo.ID].needFiles > 0" ng-click="override(repo.ID)" href=""><span class="glyphicon glyphicon-upload"></span>&emsp;Override Changes</a>
+                </span>
               </div>
             </div>
           </div>

+ 23 - 0
model/model.go

@@ -851,3 +851,26 @@ func (m *Model) State(repo string) string {
 		return "unknown"
 	}
 }
+
+func (m *Model) Override(repo string) {
+	fs := m.NeedFilesRepo(repo)
+
+	m.rmut.Lock()
+	r := m.repoFiles[repo]
+	for i := range fs {
+		f := &fs[i]
+		h := r.Get(cid.LocalID, f.Name)
+		if h.Name != f.Name {
+			// We are missing the file
+			f.Flags |= protocol.FlagDeleted
+			f.Blocks = nil
+		} else {
+			// We have the file, replace with our version
+			*f = h
+		}
+		f.Version = lamport.Default.Tick(f.Version)
+	}
+	m.rmut.Unlock()
+
+	r.Update(cid.LocalID, fs)
+}

Some files were not shown because too many files changed in this diff