fix: preserve modTime for DeleteMarker on remote disks (#9905)

This commit is contained in:
Harshavardhana 2020-06-23 10:20:31 -07:00 committed by GitHub
parent b460b5967f
commit dee3cf2d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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