From dee3cf2d7fe2d98732302a29140a33afc7daae53 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 23 Jun 2020 10:20:31 -0700 Subject: [PATCH] fix: preserve modTime for DeleteMarker on remote disks (#9905) --- cmd/storage-rest-client.go | 8 +++++--- cmd/storage-rest-server.go | 11 ++++++++--- cmd/xl-storage-format-v2.go | 13 +++++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/storage-rest-client.go b/cmd/storage-rest-client.go index a2248e5af..3c9eb6fe2 100644 --- a/cmd/storage-rest-client.go +++ b/cmd/storage-rest-client.go @@ -287,10 +287,12 @@ func (client *storageRESTClient) DeleteVersion(volume, path string, fi FileInfo) values := make(url.Values) values.Set(storageRESTVolume, volume) values.Set(storageRESTFilePath, path) - values.Set(storageRESTVersionID, fi.VersionID) - values.Set(storageRESTDeleteMarker, strconv.FormatBool(fi.Deleted)) - respBody, err := client.call(storageRESTMethodDeleteVersion, values, nil, -1) + var buffer bytes.Buffer + encoder := gob.NewEncoder(&buffer) + encoder.Encode(&fi) + + respBody, err := client.call(storageRESTMethodDeleteVersion, values, &buffer, -1) defer http.DrainBody(respBody) return err } diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index d79d703c7..050760f44 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -286,10 +286,15 @@ func (s *storageRESTServer) DeleteVersionHandler(w http.ResponseWriter, r *http. vars := mux.Vars(r) volume := vars[storageRESTVolume] filePath := vars[storageRESTFilePath] - versionID := vars[storageRESTVersionID] - deleteMarker := vars[storageRESTDeleteMarker] == "true" - err := s.storage.DeleteVersion(volume, filePath, FileInfo{VersionID: versionID, Deleted: deleteMarker}) + var fi FileInfo + decoder := gob.NewDecoder(r.Body) + if err := decoder.Decode(&fi); err != nil { + s.writeErrorResponse(w, err) + return + } + + err := s.storage.DeleteVersion(volume, filePath, fi) if err != nil { s.writeErrorResponse(w, err) } diff --git a/cmd/xl-storage-format-v2.go b/cmd/xl-storage-format-v2.go index 883148e7c..63aff863c 100644 --- a/cmd/xl-storage-format-v2.go +++ b/cmd/xl-storage-format-v2.go @@ -18,6 +18,7 @@ package cmd import ( "bytes" + "errors" "fmt" "strings" "time" @@ -230,13 +231,17 @@ func (z *xlMetaV2) AddVersion(fi FileInfo) error { if err != nil { return err } - z.Versions = append(z.Versions, xlMetaV2Version{ + v := xlMetaV2Version{ Type: DeleteType, DeleteMarker: &xlMetaV2DeleteMarker{ VersionID: uv, ModTime: fi.ModTime.UnixNano(), }, - }) + } + if !v.Valid() { + return errors.New("internal error: invalid version entry generated") + } + z.Versions = append(z.Versions, v) return nil } @@ -305,6 +310,10 @@ func (z *xlMetaV2) AddVersion(fi FileInfo) error { } } + if !ventry.Valid() { + return errors.New("internal error: invalid version entry generated") + } + for i, version := range z.Versions { if !version.Valid() { return errFileCorrupt