diff --git a/changelog/unreleased/fix-ocm-storage-checksum.md b/changelog/unreleased/fix-ocm-storage-checksum.md new file mode 100644 index 0000000000..034f240a0f --- /dev/null +++ b/changelog/unreleased/fix-ocm-storage-checksum.md @@ -0,0 +1,8 @@ +Bugfix: Add checksum to OCM storageprovider responses + +When the remote instance of the OCM storage provider returns file checksums in +its PROPFIND responses we're now passing them through to in Stat responses. +This allows e.g. the oCIS thumbnailer to work with ocm shares. + +https://github.com/cs3org/reva/pull/4908 +https://github.com/owncloud/ocis/issues/10272 diff --git a/pkg/ocm/storage/received/ocm.go b/pkg/ocm/storage/received/ocm.go index 0b1fea976d..40c6eac296 100644 --- a/pkg/ocm/storage/received/ocm.go +++ b/pkg/ocm/storage/received/ocm.go @@ -22,11 +22,13 @@ import ( "context" "crypto/tls" "encoding/base64" + "encoding/xml" "io" "io/fs" "net/http" "net/url" "path/filepath" + "regexp" "strings" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" @@ -288,9 +290,12 @@ func convertStatToResourceInfo(ref *provider.Reference, f fs.FileInfo, share *oc Etag: webdavFile.ETag(), Owner: share.Creator, PermissionSet: webdavProtocol.Permissions.Permissions, - Checksum: &provider.ResourceChecksum{ - Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_INVALID, - }, + } + + if t == provider.ResourceType_RESOURCE_TYPE_FILE { + // get SHA1 checksum from owncloud specific properties if available + propstat := webdavFile.Sys().(gowebdav.Props) + ri.Checksum = extractChecksum(propstat) } if f.(gowebdav.File).StatusCode() == 425 { @@ -300,6 +305,26 @@ func convertStatToResourceInfo(ref *provider.Reference, f fs.FileInfo, share *oc return &ri, nil } +func extractChecksum(props gowebdav.Props) *provider.ResourceChecksum { + checksums := props.GetString(xml.Name{Space: "http://owncloud.org/ns", Local: "checksums"}) + if checksums == "" { + return &provider.ResourceChecksum{ + Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_INVALID, + } + } + re := regexp.MustCompile("SHA1:(.*)") + matches := re.FindStringSubmatch(checksums) + if len(matches) == 2 { + return &provider.ResourceChecksum{ + Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_SHA1, + Sum: matches[1], + } + } + return &provider.ResourceChecksum{ + Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_INVALID, + } +} + func (d *driver) GetMD(ctx context.Context, ref *provider.Reference, _ []string, _ []string) (*provider.ResourceInfo, error) { client, share, rel, err := d.webdavClient(ctx, nil, ref) if err != nil {