delete file storage when POST to update

PUT is used to update. But sometimes POST is also used to post the same
file again. In this case, the actual file storage was not marked as
deleted.

This fix will try its best to delete the orphan files.
This commit is contained in:
Chris Lu 2016-06-03 00:24:55 -07:00
parent 535b1610c8
commit b456173eb8

View file

@ -139,6 +139,14 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
// also delete the old fid unless PUT operation
if r.Method != "PUT" {
if oldFid, err := fs.filer.FindFile(path); err == nil {
operation.DeleteFile(fs.master, oldFid, fs.jwt(oldFid))
}
}
glog.V(4).Infoln("saving", path, "=>", fileId)
if db_err := fs.filer.CreateFile(path, fileId); db_err != nil {
operation.DeleteFile(fs.master, fileId, fs.jwt(fileId)) //clean up