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

Returning custom Webdav properties #721

Merged
merged 1 commit into from
May 7, 2020
Merged
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
11 changes: 10 additions & 1 deletion internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,16 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("d:"+pf.Prop[i].Local, ""))
}
default:
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newPropNS(pf.Prop[i].Space, pf.Prop[i].Local, ""))
// handle custom properties
if k := md.GetArbitraryMetadata(); k == nil {
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newPropNS(pf.Prop[i].Space, pf.Prop[i].Local, ""))
} else if amd := k.GetMetadata(); amd == nil {
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newPropNS(pf.Prop[i].Space, pf.Prop[i].Local, ""))
} else if v, ok := amd[fmt.Sprintf("%s/%s", pf.Prop[i].Space, pf.Prop[i].Local)]; ok && v != "" {
propstatOK.Prop = append(propstatOK.Prop, s.newPropNS(pf.Prop[i].Space, pf.Prop[i].Local, v))
} else {
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newPropNS(pf.Prop[i].Space, pf.Prop[i].Local, ""))
}
}
}
if len(propstatOK.Prop) > 0 {
Expand Down
25 changes: 22 additions & 3 deletions pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,27 @@ func (fs *ocfs) convertToResourceInfo(ctx context.Context, fi os.FileInfo, np st
appctx.GetLogger(ctx).Error().Err(errtypes.UserRequired("userrequired")).Msg("error getting user from ctx")
}

metadata := map[string]string{}
list, err := xattr.List(np)
if err == nil {
for _, entry := range list {
// filter out non-custom properties
if !strings.HasPrefix(entry, mdPrefix) {
continue
}
if val, err := xattr.Get(np, entry); err == nil {
metadata[entry[len(mdPrefix):]] = string(val)
} else {
appctx.GetLogger(ctx).Error().Err(err).
Str("entry", entry).
Msgf("error retrieving xattr metadata")
}
}
} else {
appctx.GetLogger(ctx).Error().Err(err).Msg("error getting list of extended attributes")
}

metadata["http://owncloud.org/ns/favorite"] = favorite
return &provider.ResourceInfo{
Id: &provider.ResourceId{OpaqueId: id},
Path: fn,
Expand All @@ -443,9 +464,7 @@ func (fs *ocfs) convertToResourceInfo(ctx context.Context, fi os.FileInfo, np st
// TODO read nanos from where? Nanos: fi.MTimeNanos,
},
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: map[string]string{
"http://owncloud.org/ns/favorite": favorite,
},
Metadata: metadata,
},
}
}
Expand Down