Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocm: extract file checksum from owncloud specific properties #4908

Open
wants to merge 1 commit into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading