Skip to content

Commit aba48aa

Browse files
committed
bugfix: restore / view deleted file
* before restore / view a delted file the actual fh was initialized * but the file was deleted - no actual fh was found and a error was thrown
1 parent 1bb1d77 commit aba48aa

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

web.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func listSnapshotsHndl(w http.ResponseWriter, r *http.Request) {
7373
// given file was modified.
7474
params, _ := extractParams(r)
7575
if path, ok := params["where-file-modified"]; ok {
76-
logInfo.Printf("scan snapshots where file: '%s' was modified\n", path)
76+
logDebug.Printf("scan snapshots where file: '%s' was modified\n", path)
7777

7878
// if 'scan-snap-limit' is given, limit scan to the given value
7979
if scanSnapLimit, ok := params["scan-snap-limit"]; ok {
@@ -283,7 +283,14 @@ func restoreFileHndl(w http.ResponseWriter, r *http.Request) {
283283

284284
// get file-handle for the actual file
285285
actualFh, err := NewFileHandle(path)
286-
if err != nil {
286+
if err == nil {
287+
// move the actual file to the backup location if the file was found
288+
if err := actualFh.MoveToBackup(); err != nil {
289+
logError.Println(err.Error())
290+
http.Error(w, "unable to restore: "+err.Error(), 500)
291+
return
292+
}
293+
} else if err != nil && !os.IsNotExist(err) {
287294
logError.Println(err.Error())
288295
http.Error(w, "unable to restore - actual file not found: "+err.Error(), 400)
289296
return
@@ -297,13 +304,6 @@ func restoreFileHndl(w http.ResponseWriter, r *http.Request) {
297304
return
298305
}
299306

300-
// move the actual file to the backup location
301-
if err := actualFh.MoveToBackup(); err != nil {
302-
logError.Println(err.Error())
303-
http.Error(w, "unable to restore: "+err.Error(), 500)
304-
return
305-
}
306-
307307
// copy the file from the snapshot as the actual file
308308
if err := snapFh.CopyAs(path); err != nil {
309309
logError.Println(err.Error())
@@ -334,7 +334,7 @@ func diffFileHndl(w http.ResponseWriter, r *http.Request) {
334334
}
335335

336336
// get parameter context-size
337-
contextSize := 5
337+
contextSize := 5 // FIXME: from default value in main.go
338338
if contextSizeStr, ok := params["context-size"]; ok {
339339
contextSize, _ = strconv.Atoi(contextSizeStr)
340340
}
@@ -411,7 +411,7 @@ func revertChangeHndl(w http.ResponseWriter, r *http.Request) {
411411
// verify path
412412
verifyPathIsUnderZMP(path, w, r)
413413

414-
//FIXME!!
414+
//FIXME: unmarshal without json.Marshal -> json.Unmarshal hack
415415
var deltas Deltas
416416
if d, ok := params["deltas"]; ok {
417417
js, _ := json.Marshal(d)

webapp/directives.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ directive('zsdFileActions', ['$window', '$sce', '$rootScope', 'FileUtils', 'Back
123123
scope.pathInSnap = PathUtils.convertToSnapPath(p, scope.curSnap.Name);
124124

125125
// trigger fileSelected
126-
fileSelected();
126+
fileSelected(scope.pathInActual);
127127

128128
});
129129

@@ -133,7 +133,7 @@ directive('zsdFileActions', ['$window', '$sce', '$rootScope', 'FileUtils', 'Back
133133
scope.pathInSnap = PathUtils.convertToSnapPath(scope.pathInActual, snap.Name)
134134

135135
// trigger fileSelected
136-
fileSelected();
136+
fileSelected(scope.pathInActual);
137137
});
138138
}
139139

@@ -150,7 +150,7 @@ directive('zsdFileActions', ['$window', '$sce', '$rootScope', 'FileUtils', 'Back
150150
scope.pathInSnap = p;
151151

152152
// trigger fileSelected
153-
fileSelected();
153+
fileSelected(scope.pathInSnap);
154154
});
155155
}
156156

@@ -162,9 +162,9 @@ directive('zsdFileActions', ['$window', '$sce', '$rootScope', 'FileUtils', 'Back
162162

163163

164164
// trigger actions if a file is selected
165-
function fileSelected(){
165+
function fileSelected(path){
166166
// fetch file-info
167-
Backend.fileInfo(scope.pathInActual).then(function(fi){
167+
Backend.fileInfo(path).then(function(fi){
168168
scope.fileInfo = fi;
169169

170170
// for ui: enable / disable view and diff buttons

0 commit comments

Comments
 (0)