Skip to content

Commit

Permalink
ocm: extract file checksum from owncloud specific properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rhafer committed Nov 4, 2024
1 parent 0c0a322 commit 9fd53dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/fix-ocm-storage-checksum.md
Original file line number Diff line number Diff line change
@@ -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
31 changes: 28 additions & 3 deletions pkg/ocm/storage/received/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 9fd53dd

Please sign in to comment.