Skip to content

Commit

Permalink
Pass etag in quotes from the fs layer (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Jun 22, 2020
1 parent 5fb4422 commit e6cf7b4
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
// etags must be enclosed in double quotes and cannot contain them.
// See https://tools.ietf.org/html/rfc7232#section-2.3 for details
// TODO(jfd) handle weak tags that start with 'W/'
etag := fmt.Sprintf("\"%s\"", strings.Trim(md.Etag, "\""))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("d:getetag", etag))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("d:getetag", md.Etag))
}

if md.PermissionSet != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclientgrpc.FileInf
Id: &provider.ResourceId{OpaqueId: fmt.Sprintf("%d", eosFileInfo.Inode)},
Path: path,
Owner: &userpb.UserId{OpaqueId: username},
Etag: eosFileInfo.ETag,
Etag: fmt.Sprintf("\"%s\"", strings.Trim(eosFileInfo.ETag, "\"")),
MimeType: mime.Detect(eosFileInfo.IsDir, path),
Size: size,
PermissionSet: &provider.ResourcePermissions{ListContainer: true, CreateContainer: true},
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,8 @@ func (fs *ocfs) SetArbitraryMetadata(ctx context.Context, ref *provider.Referenc
// TODO(jfd) any other metadata that is interesting? fileid?
if val, ok := md.Metadata["etag"]; ok {
etag := calcEtag(ctx, fi)
if etag == md.Metadata["etag"] {
val = fmt.Sprintf("\"%s\"", strings.Trim(val, "\""))
if etag == val {
log.Debug().
Str("np", np).
Str("etag", val).
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/fs/owncloud/owncloud_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/binary"
"fmt"
"os"
"strings"
"syscall"

"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -62,5 +63,6 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
if err != nil {
log.Error().Err(err).Msg("error writing size")
}
return fmt.Sprintf(`"%x"`, h.Sum(nil))
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}
4 changes: 3 additions & 1 deletion pkg/storage/fs/owncloud/owncloud_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/binary"
"fmt"
"os"
"strings"

"github.com/cs3org/reva/pkg/appctx"
)
Expand All @@ -48,5 +49,6 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
if err != nil {
log.Error().Err(err).Msg("error writing size")
}
return fmt.Sprintf(`"%x"`, h.Sum(nil))
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}
2 changes: 1 addition & 1 deletion pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) *
Id: &provider.ResourceId{OpaqueId: fmt.Sprintf("%d", eosFileInfo.Inode)},
Path: path,
Owner: &userpb.UserId{OpaqueId: username},
Etag: eosFileInfo.ETag,
Etag: fmt.Sprintf("\"%s\"", strings.Trim(eosFileInfo.ETag, "\"")),
MimeType: mime.Detect(eosFileInfo.IsDir, path),
Size: size,
PermissionSet: &provider.ResourcePermissions{ListContainer: true, CreateContainer: true},
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/utils/localfs/localfs_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/binary"
"fmt"
"os"
"strings"
"syscall"

"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -60,5 +61,6 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
if err != nil {
log.Error().Err(err).Msg("error writing size")
}
return fmt.Sprintf(`"%x"`, h.Sum(nil))
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}
4 changes: 3 additions & 1 deletion pkg/storage/utils/localfs/localfs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/binary"
"fmt"
"os"
"strings"

"github.com/cs3org/reva/pkg/appctx"
)
Expand All @@ -48,5 +49,6 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
if err != nil {
log.Error().Err(err).Msg("error writing size")
}
return fmt.Sprintf(`"%x"`, h.Sum(nil))
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

0 comments on commit e6cf7b4

Please sign in to comment.