mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-27 18:45:04 -05:00
Merge branch 'origin/main' into 'next-release/main'
This commit is contained in:
commit
4fef92fb9b
25 files changed
+392
-516
No files matched your search
@@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Purpose of this script is to parse the go.mod file to retrieve the version of
|
||||
# Go that we are using, either from a "toolchain" directive (preferred), or from
|
||||
# a "go" directive as a fallback.
|
||||
#
|
||||
# The script then outputs that version, where it will be picked up as an environment
|
||||
# variable in mise.
|
||||
|
||||
F="./go.mod"
|
||||
|
||||
AWK=awk
|
||||
# prefer 'gawk' over 'awk' to make sure we get GNU awk
|
||||
command -v gawk &>/dev/null && AWK=gawk
|
||||
|
||||
[[ -e $F ]] || { echo "ERROR: failed to find $F" >&2; exit 1;}
|
||||
|
||||
GO_VERSION=$("$AWK" '/^toolchain/ {print $2; exit} /^go / {print $2}' "$F")
|
||||
GO_VERSION=${GO_VERSION#go} # strip the potential 'go' prefix:
|
||||
echo "${GO_VERSION}"
|
||||
@@ -68,7 +68,7 @@ require (
|
||||
github.com/open-policy-agent/opa v1.21.1
|
||||
github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89
|
||||
github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e
|
||||
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec
|
||||
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3
|
||||
github.com/opensearch-project/opensearch-go/v4 v4.7.3
|
||||
github.com/orcaman/concurrent-map v1.0.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
|
||||
@@ -761,8 +761,8 @@ github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89 h1:W1ms+l
|
||||
github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89/go.mod h1:vigJkNss1N2QEceCuNw/ullDehncuJNFB6mEnzfq9UI=
|
||||
github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e h1:5sf3dNw/eYuuvDL8+3c4pbPSX+Pblw6lsylGtq+cw30=
|
||||
github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e/go.mod h1:lTM8JeGblNpoMySTW7Lui2+c5TTLI95mwxtdUIHHrhU=
|
||||
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec h1:3Y/o9uwiQ07c5Od1E/6TQQPDzN2uHeOACzW+d/+KGBQ=
|
||||
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec/go.mod h1:lwylaua29K7ge30pFxzHMh6LeH9bhCQduFdw+qKFzJA=
|
||||
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3 h1:lB4loaAtlU4J5OzZBcIOFDUozjRiltnMJZpqy9gonI0=
|
||||
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3/go.mod h1:oqi8rN/Nt2v+Gn/dmY9p2Zct3VHrdvnYtqZWHrjij7M=
|
||||
github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4 h1:l2oB/RctH+t8r7QBj5p8thfEHCM/jF35aAY3WQ3hADI=
|
||||
github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40=
|
||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[env]
|
||||
GO_VERSION = "{{ exec(command='./.mise-go-version.sh') }}"
|
||||
[settings]
|
||||
# take the Go version from go.mod (the toolchain directive, else the go directive)
|
||||
idiomatic_version_file_enable_tools = ["go"]
|
||||
|
||||
[tools]
|
||||
go = "{{ env.GO_VERSION }}"
|
||||
node = "24"
|
||||
pnpm = "11.1.3"
|
||||
"go:github.com/go-delve/delve/cmd/dlv" = "1.27.1"
|
||||
|
||||
@@ -73,7 +73,10 @@ func check(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
lu, backend := getBackend(cmd)
|
||||
lu, backend, err := getBackend(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o := &options.Options{
|
||||
MetadataBackend: backend.Name(),
|
||||
MaxConcurrency: 100,
|
||||
@@ -192,7 +195,10 @@ func dumpCmd(_ *config.Config) *cobra.Command {
|
||||
Use: "dump",
|
||||
Short: `print the metadata of the given node. String attributes will be enclosed in quotes. Binary attributes will be returned encoded as base64 with their value being prefixed with '0s'.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
lu, backend := getBackend(cmd)
|
||||
lu, backend, err := getBackend(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path, err := getNode(cmd, lu)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -215,7 +221,10 @@ func getCmd(_ *config.Config) *cobra.Command {
|
||||
Use: "get",
|
||||
Short: `print a specific attribute of the given node. String attributes will be enclosed in quotes. Binary attributes will be returned encoded as base64 with their value being prefixed with '0s'.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
lu, backend := getBackend(cmd)
|
||||
lu, backend, err := getBackend(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path, err := getNode(cmd, lu)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -240,7 +249,10 @@ func setCmd(_ *config.Config) *cobra.Command {
|
||||
Use: "set",
|
||||
Short: `manipulate metadata of the given node. Binary attributes can be given hex encoded (prefix by '0x') or base64 encoded (prefix by '0s').`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
lu, backend := getBackend(cmd)
|
||||
lu, backend, err := getBackend(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := getNode(cmd, lu)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -281,26 +293,31 @@ func setCmd(_ *config.Config) *cobra.Command {
|
||||
return sCmd
|
||||
}
|
||||
|
||||
func backend(backend string) metadata.Backend {
|
||||
switch backend {
|
||||
case "xattrs":
|
||||
return metadata.NewXattrsBackend(cache.Config{})
|
||||
// backend returns the metadata backend with the given name. Only the
|
||||
// messagepack backend is supported.
|
||||
func backend(name string) (metadata.Backend, error) {
|
||||
switch name {
|
||||
case "mpk":
|
||||
return metadata.NewMessagePackBackend(cache.Config{})
|
||||
return metadata.NewMessagePackBackend(cache.Config{}), nil
|
||||
}
|
||||
return metadata.NullBackend{}
|
||||
return nil, fmt.Errorf("unsupported metadata backend %q", name)
|
||||
}
|
||||
|
||||
func getBackend(cmd *cobra.Command) (*lookup.Lookup, metadata.Backend) {
|
||||
// getBackend detects the metadata backend in the storage under --root. It
|
||||
// fails when no supported backend is found, e.g. because --root is wrong.
|
||||
func getBackend(cmd *cobra.Command) (*lookup.Lookup, metadata.Backend, error) {
|
||||
rootFlag, _ := cmd.Flags().GetString("root")
|
||||
|
||||
bod := lookup.DetectBackendOnDisk(rootFlag)
|
||||
backend := backend(bod)
|
||||
backend, err := backend(bod)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not read the metadata in %q: %w", rootFlag, err)
|
||||
}
|
||||
lu := lookup.New(backend, &options.Options{
|
||||
Root: rootFlag,
|
||||
MetadataBackend: bod,
|
||||
}, &timemanager.Manager{})
|
||||
return lu, backend
|
||||
return lu, backend, nil
|
||||
}
|
||||
|
||||
func getNode(cmd *cobra.Command, lu *lookup.Lookup) (*node.Node, error) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/opencloud-eu/reva/v3/pkg/storage/pkg/decomposedfs/metadata"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/test-go/testify/require"
|
||||
)
|
||||
|
||||
func TestBackend(t *testing.T) {
|
||||
t.Run("selects messagepack", func(t *testing.T) {
|
||||
b, err := backend("mpk")
|
||||
require.NoError(t, err)
|
||||
require.IsType(t, metadata.MessagePackBackend{}, b)
|
||||
})
|
||||
|
||||
for _, bod := range []string{"xattrs", "ini", "unknown", ""} {
|
||||
t.Run("rejects the unsupported backend "+bod, func(t *testing.T) {
|
||||
b, err := backend(bod)
|
||||
require.EqualError(t, err, `unsupported metadata backend "`+bod+`"`)
|
||||
require.Nil(t, b)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBackend(t *testing.T) {
|
||||
t.Run("fails when no supported metadata backend is found on disk", func(t *testing.T) {
|
||||
cmd := &cobra.Command{}
|
||||
cmd.Flags().String("root", t.TempDir(), "")
|
||||
|
||||
lu, b, err := getBackend(cmd)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "unsupported metadata backend")
|
||||
require.Nil(t, lu)
|
||||
require.Nil(t, b)
|
||||
})
|
||||
}
|
||||
@@ -11,7 +11,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-10-31 23:16+0000\n"
|
||||
"POT-Creation-Date: 2026-11-20 23:16+0000\n"
|
||||
"PO-Revision-Date: 2025-01-27 10:17+0000\n"
|
||||
"Last-Translator: Daniel Nylander <po@danielnylander.se>, 2026\n"
|
||||
"Language-Team: Swedish (https://app.transifex.com/opencloud-eu/teams/204053/sv/)\n"
|
||||
|
||||
@@ -339,8 +339,21 @@ Example File:
|
||||
{
|
||||
"id": "016f6ddd-9501-4a0a-8ebe-64a20ee8ec82",
|
||||
"name": "Drives.List",
|
||||
"displayName": "List All Spaces",
|
||||
"description": "This permission allows listing all spaces.",
|
||||
"displayName": "List All Project Spaces",
|
||||
"description": "This permission allows listing all project spaces.",
|
||||
"permissionValue": {
|
||||
"operation": "OPERATION_READ",
|
||||
"constraint": "CONSTRAINT_ALL"
|
||||
},
|
||||
"resource": {
|
||||
"type": "TYPE_SYSTEM"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "b7c1f1d6-64fb-4c42-aad1-928aca0970e8",
|
||||
"name": "Drives.ListPersonal",
|
||||
"displayName": "List All Personal Spaces",
|
||||
"description": "This permission allows listing all personal spaces.",
|
||||
"permissionValue": {
|
||||
"operation": "OPERATION_READ",
|
||||
"constraint": "CONSTRAINT_ALL"
|
||||
@@ -352,8 +365,21 @@ Example File:
|
||||
{
|
||||
"id": "b44b4054-31a2-42b8-bb71-968b15cfbd4f",
|
||||
"name": "Drives.ReadWrite",
|
||||
"displayName": "Manage space properties",
|
||||
"description": "This permission allows managing space properties such as name and description.",
|
||||
"displayName": "Manage project space properties",
|
||||
"description": "This permission allows managing project space properties such as name and description.",
|
||||
"permissionValue": {
|
||||
"operation": "OPERATION_READWRITE",
|
||||
"constraint": "CONSTRAINT_ALL"
|
||||
},
|
||||
"resource": {
|
||||
"type": "TYPE_SYSTEM"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "1759d0ab-201b-4e22-af09-992531cbdf92",
|
||||
"name": "Drives.ReadWritePersonal",
|
||||
"displayName": "Manage personal space properties",
|
||||
"description": "This permission allows managing personal space properties such as name and description.",
|
||||
"permissionValue": {
|
||||
"operation": "OPERATION_READWRITE",
|
||||
"constraint": "CONSTRAINT_ALL"
|
||||
|
||||
@@ -94,7 +94,9 @@ func ServiceAccountBundle() *settingsmsg.Bundle {
|
||||
GroupManagementPermission(All),
|
||||
LanguageManagementPermission(All),
|
||||
ListFavoritesPermission(All),
|
||||
ListPersonalSpacesPermission(All),
|
||||
ListSpacesPermission(All),
|
||||
ManagePersonalSpacePropertiesPermission(All),
|
||||
ManageSpacePropertiesPermission(All),
|
||||
RoleManagementPermission(All),
|
||||
SetPersonalSpaceQuotaPermission(All),
|
||||
@@ -145,7 +147,9 @@ func generateBundleAdminRole() *settingsmsg.Bundle {
|
||||
GroupManagementPermission(All),
|
||||
LanguageManagementPermission(All),
|
||||
ListFavoritesPermission(Own),
|
||||
ListPersonalSpacesPermission(All),
|
||||
ListSpacesPermission(All),
|
||||
ManagePersonalSpacePropertiesPermission(All),
|
||||
ManageSpacePropertiesPermission(All),
|
||||
RoleManagementPermission(All),
|
||||
SetPersonalSpaceQuotaPermission(All),
|
||||
|
||||
@@ -524,13 +524,13 @@ func ListFavoritesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.S
|
||||
}
|
||||
}
|
||||
|
||||
// ListSpacesPermission is the permission to list spaces
|
||||
func ListSpacesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.Setting {
|
||||
// ListPersonalSpacesPermission is the permission to list personal spaces
|
||||
func ListPersonalSpacesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.Setting {
|
||||
return &settingsmsg.Setting{
|
||||
Id: "016f6ddd-9501-4a0a-8ebe-64a20ee8ec82",
|
||||
Name: "Drives.List",
|
||||
DisplayName: "List All Spaces",
|
||||
Description: "This permission allows listing all spaces.",
|
||||
Id: "b7c1f1d6-64fb-4c42-aad1-928aca0970e8",
|
||||
Name: "Drives.ListPersonal",
|
||||
DisplayName: "List All Personal Spaces",
|
||||
Description: "This permission allows listing all personal spaces.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
@@ -543,13 +543,51 @@ func ListSpacesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.Sett
|
||||
}
|
||||
}
|
||||
|
||||
// ListSpacesPermission is the permission to list spaces
|
||||
func ListSpacesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.Setting {
|
||||
return &settingsmsg.Setting{
|
||||
Id: "016f6ddd-9501-4a0a-8ebe-64a20ee8ec82",
|
||||
Name: "Drives.List",
|
||||
DisplayName: "List All Project Spaces",
|
||||
Description: "This permission allows listing all project spaces.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
Value: &settingsmsg.Setting_PermissionValue{
|
||||
PermissionValue: &settingsmsg.Permission{
|
||||
Operation: settingsmsg.Permission_OPERATION_READ,
|
||||
Constraint: c,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ManagePersonalSpacePropertiesPermission is the permission to manage personal space properties
|
||||
func ManagePersonalSpacePropertiesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.Setting {
|
||||
return &settingsmsg.Setting{
|
||||
Id: "1759d0ab-201b-4e22-af09-992531cbdf92",
|
||||
Name: "Drives.ReadWritePersonal",
|
||||
DisplayName: "Manage personal space properties",
|
||||
Description: "This permission allows managing personal space properties such as name and description.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
Value: &settingsmsg.Setting_PermissionValue{
|
||||
PermissionValue: &settingsmsg.Permission{
|
||||
Operation: settingsmsg.Permission_OPERATION_READWRITE,
|
||||
Constraint: c,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ManageSpacePropertiesPermission is the permission to manage space properties
|
||||
func ManageSpacePropertiesPermission(c settingsmsg.Permission_Constraint) *settingsmsg.Setting {
|
||||
return &settingsmsg.Setting{
|
||||
Id: "b44b4054-31a2-42b8-bb71-968b15cfbd4f",
|
||||
Name: "Drives.ReadWrite",
|
||||
DisplayName: "Manage space properties",
|
||||
Description: "This permission allows managing space properties such as name and description.",
|
||||
DisplayName: "Manage project space properties",
|
||||
Description: "This permission allows managing project space properties such as name and description.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
|
||||
@@ -1180,13 +1180,9 @@ Feature: get users
|
||||
| Admin | Space Admin |
|
||||
| Admin | User |
|
||||
| Admin | User Light |
|
||||
| Space Admin | Admin |
|
||||
| Space Admin | Space Admin |
|
||||
| Space Admin | User |
|
||||
| Space Admin | User Light |
|
||||
|
||||
|
||||
Scenario Outline: non-admin user tries to get drive information of other user with different user role
|
||||
Scenario Outline: non-admin or space admin user tries to get drive information of other user with different user role
|
||||
Given the administrator has assigned the role "<user-role>" to user "Alice" using the Graph API
|
||||
And the administrator has assigned the role "<user-role-2>" to user "Brian" using the Graph API
|
||||
When user "Alice" gets the personal drive information of user "Brian" using Graph API
|
||||
@@ -1220,15 +1216,19 @@ Feature: get users
|
||||
}
|
||||
"""
|
||||
Examples:
|
||||
| user-role | user-role-2 |
|
||||
| User | Admin |
|
||||
| User | Space Admin |
|
||||
| User | User |
|
||||
| User | User Light |
|
||||
| User Light | Admin |
|
||||
| User Light | Space Admin |
|
||||
| User Light | User |
|
||||
| User Light | User Light |
|
||||
| user-role | user-role-2 |
|
||||
| Space Admin | Admin |
|
||||
| Space Admin | Space Admin |
|
||||
| Space Admin | User |
|
||||
| Space Admin | User Light |
|
||||
| User | Admin |
|
||||
| User | Space Admin |
|
||||
| User | User |
|
||||
| User | User Light |
|
||||
| User Light | Admin |
|
||||
| User Light | Space Admin |
|
||||
| User Light | User |
|
||||
| User Light | User Light |
|
||||
|
||||
|
||||
Scenario Outline: user with different user role gets his/her own drive information
|
||||
|
||||
@@ -49,34 +49,10 @@ Feature: Space management
|
||||
And the json response should not contain a space with name "Alice Hansen"
|
||||
|
||||
|
||||
Scenario: space admin user can see another personal spaces
|
||||
Scenario: space admin user cannot see another personal spaces
|
||||
When user "Brian" lists all spaces via the Graph API with query "$filter=driveType eq 'personal'"
|
||||
Then the HTTP status code should be "200"
|
||||
And the JSON response should contain space called "Alice Hansen" and match
|
||||
"""
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"driveType",
|
||||
"name",
|
||||
"id"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"enum": ["Alice Hansen"]
|
||||
},
|
||||
"driveType": {
|
||||
"type": "string",
|
||||
"enum": ["personal"]
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"enum": ["%space_id%"]
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the json response should not contain a space with name "Alice Hansen"
|
||||
And the json response should not contain a space with name "Project"
|
||||
|
||||
|
||||
@@ -155,10 +131,8 @@ Feature: Space management
|
||||
Then the HTTP status code should be "<code>"
|
||||
Examples:
|
||||
| user | code |
|
||||
# Brian is Space Admin and can currently list all Personal Spaces, so he
|
||||
# gets a 403 instead of a 404 here. This might change in the future see:
|
||||
# https://github.com/opencloud-eu/opencloud/issues/2979
|
||||
| Brian | 403 |
|
||||
# The Space Admin role has no permission to list personal spaces, so Brian gets 404 like Carol
|
||||
| Brian | 404 |
|
||||
| Carol | 404 |
|
||||
|
||||
|
||||
|
||||
+1
-6
@@ -159,11 +159,6 @@ func New(o *options.Options, stream events.Stream, cache, historyCache *idcache.
|
||||
|
||||
var lu *lookup.Lookup
|
||||
switch o.MetadataBackend {
|
||||
case "xattrs":
|
||||
lu, err = lookup.New(metadata.NewXattrsBackend(o.FileMetadataCache), um, o, &timemanager.Manager{}, cache, historyCache, log)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "hybrid":
|
||||
lu, err = lookup.New(metadata.NewHybridBackend(1024, // start offloading grants after 1KB
|
||||
func(n metadata.MetadataNode) string {
|
||||
@@ -179,7 +174,7 @@ func New(o *options.Options, stream events.Stream, cache, historyCache *idcache.
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown metadata backend %s, only 'xattrs' or 'hybrid' (default) supported", o.MetadataBackend)
|
||||
return nil, fmt.Errorf("unknown metadata backend %s, only 'hybrid' (default) supported", o.MetadataBackend)
|
||||
}
|
||||
|
||||
permissionsSelector, err := pool.PermissionsSelector(o.PermissionsSVC, pool.WithTLSMode(o.PermTLSMode))
|
||||
|
||||
Generated
Vendored
+23
@@ -140,6 +140,10 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
|
||||
}
|
||||
if revision == nil {
|
||||
appctx.GetLogger(ctx).Info().Str("nodeid", n.ID).Str("sessionid", sessionID).Msg("upload was superseded and has no revision, discarding its bytes")
|
||||
// a newer upload took over the node, nothing references the old blob anymore
|
||||
if source.ObsoleteBlobID != sessionID {
|
||||
fs.deleteObsoleteBlob(ctx, n, source.ObsoleteBlobID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
@@ -160,6 +164,12 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
|
||||
return errors.Wrap(err, "Decomposedfs: failed to write blob")
|
||||
}
|
||||
|
||||
// the node points to the new content now: the blob it pointed to before has no
|
||||
// reference left
|
||||
if source.ObsoleteBlobID != sessionID {
|
||||
fs.deleteObsoleteBlob(ctx, n, source.ObsoleteBlobID)
|
||||
}
|
||||
|
||||
// on the node that holds the content, not the session: the session is deleted when the
|
||||
// upload finishes
|
||||
if !source.ScanDate.IsZero() {
|
||||
@@ -194,6 +204,19 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteObsoleteBlob deletes the blob an upload replaced, while the caller holds the node
|
||||
// lock. It is kept if it is the one the node points to. A failure is only logged: the upload
|
||||
// is done, and a leaked blob is better than a failed upload.
|
||||
func (fs *Decomposedfs) deleteObsoleteBlob(ctx context.Context, n *node.Node, blobID string) {
|
||||
if blobID == "" || blobID == n.BlobID {
|
||||
return
|
||||
}
|
||||
blobNode := node.New(n.SpaceID, n.ID, "", "", 0, blobID, provider.ResourceType_RESOURCE_TYPE_FILE, nil, fs.lu)
|
||||
if err := fs.tp.DeleteBlob(blobNode); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Str("blobid", blobID).Msg("could not delete the obsolete blob")
|
||||
}
|
||||
}
|
||||
|
||||
// removeRevisions deletes the revisions of n that were kept only for a rollback, with their
|
||||
// blobs, while the caller holds the node lock: the ones of uploads that were rolled back,
|
||||
// and the snapshots taken with versioning disabled.
|
||||
|
||||
Generated
Vendored
+51
-9
@@ -78,6 +78,10 @@ const (
|
||||
CtxKeySpaceGID CtxKey = iota
|
||||
)
|
||||
|
||||
// maxDownloadAttempts is the number of times Download tries to open the blob of a node
|
||||
// whose blob id changed in the meantime.
|
||||
const maxDownloadAttempts = 3
|
||||
|
||||
var (
|
||||
tracer trace.Tracer
|
||||
|
||||
@@ -136,12 +140,10 @@ func NewDefault(m map[string]interface{}, bs node.Blobstore, es events.Stream, l
|
||||
|
||||
var lu *lookup.Lookup
|
||||
switch o.MetadataBackend {
|
||||
case "xattrs":
|
||||
lu = lookup.New(metadata.NewXattrsBackend(o.FileMetadataCache), o, &timemanager.Manager{})
|
||||
case "messagepack":
|
||||
lu = lookup.New(metadata.NewMessagePackBackend(o.FileMetadataCache), o, &timemanager.Manager{})
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown metadata backend %s, only 'messagepack' or 'xattrs' (default) supported", o.MetadataBackend)
|
||||
return nil, fmt.Errorf("unknown metadata backend %s, only 'messagepack' (default) supported", o.MetadataBackend)
|
||||
}
|
||||
|
||||
permissionsSelector, err := pool.PermissionsSelector(o.PermissionsSVC, pool.WithTLSMode(o.PermTLSMode))
|
||||
@@ -376,7 +378,7 @@ func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) (
|
||||
switch {
|
||||
case err != nil:
|
||||
return 0, 0, 0, err
|
||||
case !rp.GetQuota && !fs.p.ListAllSpaces(ctx):
|
||||
case !rp.GetQuota && !fs.canListAllSpaces(ctx, n):
|
||||
f, _ := storagespace.FormatReference(ref)
|
||||
if rp.Stat {
|
||||
return 0, 0, 0, errtypes.PermissionDenied(f)
|
||||
@@ -992,14 +994,54 @@ func (fs *Decomposedfs) Download(ctx context.Context, ref *provider.Reference, o
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var reader io.ReadCloser
|
||||
if openReaderFunc(ri) {
|
||||
reader, err = fs.tp.ReadBlob(n)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "Decomposedfs: error download blob '"+n.ID+"'")
|
||||
// A concurrent upload finalization can replace and delete the blob between resolving
|
||||
// the node and opening the blob. If opening fails and the blob id of the node has
|
||||
// changed, retry with the new blob.
|
||||
log := appctx.GetLogger(ctx)
|
||||
for attempt := 1; ; attempt++ {
|
||||
reader, err := fs.tp.ReadBlob(n)
|
||||
if err == nil {
|
||||
return ri, reader, nil
|
||||
}
|
||||
err = errors.Wrap(err, "Decomposedfs: error download blob '"+n.ID+"'")
|
||||
if attempt == maxDownloadAttempts {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
currentNode, readErr := node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, "", true, n.SpaceRoot, false)
|
||||
if readErr != nil {
|
||||
log.Warn().Err(readErr).AnErr("blobError", err).Str("nodeid", n.ID).Msg("could not re-read node after failing to open blob")
|
||||
return nil, nil, err
|
||||
}
|
||||
if !currentNode.Exists {
|
||||
return nil, nil, errtypes.NotFound(filepath.Join(n.ParentID, n.Name))
|
||||
}
|
||||
// a newer upload may have marked the node as processing, its blob is not written yet.
|
||||
if currentNode.IsProcessing(ctx) {
|
||||
return nil, nil, errtypes.TooEarly("file is still being processed")
|
||||
}
|
||||
if currentNode.BlobID != n.BlobID {
|
||||
// the blob was replaced: retry with the new one
|
||||
refreshed, riErr := currentNode.AsResourceInfo(ctx, rp, nil, []string{"size", "mimetype", "etag"}, true)
|
||||
if riErr != nil {
|
||||
log.Warn().Err(err).Str("nodeid", n.ID).Msg("dropped blob error, could not refresh resource info of replaced blob")
|
||||
return nil, nil, riErr
|
||||
}
|
||||
log.Debug().
|
||||
Err(err).
|
||||
Str("nodeid", n.ID).
|
||||
Str("oldblobid", n.BlobID).
|
||||
Str("newblobid", currentNode.BlobID).
|
||||
Int("attempt", attempt).
|
||||
Msg("blob was replaced while opening it, retrying")
|
||||
n, ri = currentNode, refreshed
|
||||
continue
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
return ri, reader, nil
|
||||
return ri, nil, nil
|
||||
}
|
||||
|
||||
// GetLock returns an existing lock on the given reference
|
||||
|
||||
Generated
Vendored
+4
-6
@@ -357,7 +357,9 @@ func (lu *Lookup) TimeManager() node.TimeManager {
|
||||
return lu.tm
|
||||
}
|
||||
|
||||
// DetectBackendOnDisk returns the name of the metadata backend being used on disk
|
||||
// DetectBackendOnDisk returns the name of the metadata backend being used on
|
||||
// disk: "mpk" for messagepack, or "unknown" when the storage has no space with
|
||||
// messagepack metadata, e.g. because root is wrong.
|
||||
func DetectBackendOnDisk(root string) string {
|
||||
matches, _ := filepath.Glob(filepath.Join(root, "spaces", "*", "*"))
|
||||
if len(matches) > 0 {
|
||||
@@ -370,10 +372,6 @@ func DetectBackendOnDisk(root string) string {
|
||||
if err == nil {
|
||||
return "mpk"
|
||||
}
|
||||
_, err = os.Stat(filepath.Join(base, "nodes", spaceRoot+".ini"))
|
||||
if err == nil {
|
||||
return "ini"
|
||||
}
|
||||
}
|
||||
return "xattrs"
|
||||
return "unknown"
|
||||
}
|
||||
Generated
Vendored
-354
@@ -1,354 +0,0 @@
|
||||
// Copyright 2018-2023 CERN
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/opencloud-eu/reva/v3/pkg/storage/cache"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/storage/pkg/decomposedfs/metadata/prefixes"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/storage/utils/filelocks"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pkg/xattr"
|
||||
)
|
||||
|
||||
// XattrsBackend stores the file attributes in extended attributes
|
||||
type XattrsBackend struct {
|
||||
metaCache cache.FileMetadataCache
|
||||
metrics *backendMetrics
|
||||
}
|
||||
|
||||
// NewMessageBackend returns a new XattrsBackend instance
|
||||
func NewXattrsBackend(o cache.Config) XattrsBackend {
|
||||
return XattrsBackend{
|
||||
metaCache: cache.GetFileMetadataCache(o),
|
||||
metrics: newBackendMetrics("xattrs"),
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the name of the backend
|
||||
func (XattrsBackend) Name() string { return "xattrs" }
|
||||
|
||||
// IdentifyPath returns the space id, node id and mtime of a file
|
||||
func (b XattrsBackend) IdentifyPath(_ context.Context, path string) (string, string, string, time.Time, error) {
|
||||
b.metrics.reads.Inc()
|
||||
spaceID, _ := xattr.Get(path, prefixes.SpaceIDAttr)
|
||||
id, _ := xattr.Get(path, prefixes.IDAttr)
|
||||
parentID, _ := xattr.Get(path, prefixes.ParentidAttr)
|
||||
|
||||
mtimeAttr, _ := xattr.Get(path, prefixes.MTimeAttr)
|
||||
mtime, _ := time.Parse(time.RFC3339Nano, string(mtimeAttr))
|
||||
return string(spaceID), string(id), string(parentID), mtime, nil
|
||||
}
|
||||
|
||||
// Get an extended attribute value for the given key
|
||||
// No file locking is involved here as reading a single xattr is
|
||||
// considered to be atomic.
|
||||
func (b XattrsBackend) Get(ctx context.Context, n MetadataNode, key string) ([]byte, error) {
|
||||
attribs := map[string][]byte{}
|
||||
err := b.metaCache.PullFromCache(b.cacheKey(n), &attribs)
|
||||
found := err == nil && len(attribs[key]) > 0
|
||||
b.metrics.cacheLookup(found)
|
||||
if found {
|
||||
return attribs[key], err
|
||||
}
|
||||
|
||||
b.metrics.reads.Inc()
|
||||
return xattr.Get(n.InternalPath(), key)
|
||||
}
|
||||
|
||||
// GetInt64 reads a string as int64 from the xattrs
|
||||
func (b XattrsBackend) GetInt64(ctx context.Context, n MetadataNode, key string) (int64, error) {
|
||||
attr, err := b.Get(ctx, n, key)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
v, err := strconv.ParseInt(string(attr), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (b XattrsBackend) list(ctx context.Context, n MetadataNode, acquireLock bool) (attribs []string, err error) {
|
||||
filePath := n.InternalPath()
|
||||
attrs, err := listXattr(ctx, filePath)
|
||||
if err == nil {
|
||||
return attrs, nil
|
||||
}
|
||||
|
||||
// E2BIG means the attribute name list exceeds the maximum size the kernel
|
||||
// returns (64KiB VFS limit, e.g. on XFS). It is not transient: fail fast
|
||||
// instead of paying for the locked retry below.
|
||||
if isTooBigError(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// listing xattrs failed, try again, either with lock or without
|
||||
if acquireLock {
|
||||
lockPath := filePath + filelocks.LockFileSuffix
|
||||
var f *heldLock
|
||||
locked := true
|
||||
if IsReadOnly(ctx) {
|
||||
// lock only an existing lock file, and don't lock without one
|
||||
f, locked, err = lockExisting(n, lockPath, os.O_WRONLY, b.metrics)
|
||||
} else {
|
||||
f, err = lockFile(n, lockPath, os.O_CREATE|os.O_WRONLY, b.metrics)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if locked {
|
||||
n.SetLockHeld(true)
|
||||
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
|
||||
defer func() {
|
||||
n.SetLockHeld(false)
|
||||
_ = f.Close()
|
||||
}()
|
||||
}
|
||||
}
|
||||
return listXattr(ctx, filePath)
|
||||
}
|
||||
|
||||
// All reads all extended attributes for a node. It acquires a shared file lock
|
||||
// unless the caller already holds the node's metadata lock (n.LockHeld()).
|
||||
func (b XattrsBackend) All(ctx context.Context, n MetadataNode) (map[string][]byte, error) {
|
||||
return b.getAll(ctx, n, false, !n.LockHeld())
|
||||
}
|
||||
|
||||
// Reload reads all extended attributes for a node from storage, never from the cache,
|
||||
// and updates the cache with them. It acquires a shared file lock unless the caller
|
||||
// already holds the node's metadata lock (n.LockHeld()).
|
||||
func (b XattrsBackend) Reload(ctx context.Context, n MetadataNode) (map[string][]byte, error) {
|
||||
attribs, err := b.getAll(ctx, n, true, !n.LockHeld())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(attribs) == 0 {
|
||||
// getAll doesn't cache a node without attributes, so the stale entry would stay
|
||||
if err := b.metaCache.PushToCache(b.cacheKey(n), attribs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return attribs, nil
|
||||
}
|
||||
|
||||
func (b XattrsBackend) getAll(ctx context.Context, n MetadataNode, skipCache, acquireLock bool) (map[string][]byte, error) {
|
||||
attribs := map[string][]byte{}
|
||||
|
||||
if !skipCache {
|
||||
err := b.metaCache.PullFromCache(b.cacheKey(n), &attribs)
|
||||
b.metrics.cacheLookup(err == nil)
|
||||
if err == nil {
|
||||
return attribs, err
|
||||
}
|
||||
}
|
||||
|
||||
b.metrics.reads.Inc()
|
||||
attrNames, err := b.list(ctx, n, acquireLock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(attrNames) == 0 {
|
||||
return attribs, nil
|
||||
}
|
||||
|
||||
var (
|
||||
xerrs = 0
|
||||
xerr error
|
||||
)
|
||||
// error handling: Count if there are errors while reading all attribs.
|
||||
// if there were any, return an error.
|
||||
attribs = make(map[string][]byte, len(attrNames))
|
||||
path := n.InternalPath()
|
||||
for _, name := range attrNames {
|
||||
var val []byte
|
||||
if val, xerr = xattr.Get(path, name); xerr != nil && !IsAttrUnset(xerr) {
|
||||
xerrs++
|
||||
} else {
|
||||
attribs[name] = val
|
||||
}
|
||||
}
|
||||
|
||||
if xerrs > 0 {
|
||||
return nil, errors.Wrap(xerr, "Failed to read all xattrs")
|
||||
}
|
||||
|
||||
err = b.metaCache.PushToCache(b.cacheKey(n), attribs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return attribs, nil
|
||||
}
|
||||
|
||||
// Set sets one attribute for the given path
|
||||
func (b XattrsBackend) Set(ctx context.Context, n MetadataNode, key string, val []byte) (err error) {
|
||||
return b.SetMultiple(ctx, n, map[string][]byte{key: val})
|
||||
}
|
||||
|
||||
// SetMultiple sets a set of attribute for the given path
|
||||
func (b XattrsBackend) SetMultiple(ctx context.Context, n MetadataNode, attribs map[string][]byte) (err error) {
|
||||
path := n.InternalPath()
|
||||
if !n.LockHeld() {
|
||||
err := os.MkdirAll(filepath.Dir(path), 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lockedFile, err := lockFile(n, b.LockfilePath(n), os.O_CREATE|os.O_WRONLY, b.metrics)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.SetLockHeld(true)
|
||||
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
|
||||
defer func() {
|
||||
n.SetLockHeld(false)
|
||||
_ = lockedFile.Close()
|
||||
}()
|
||||
}
|
||||
|
||||
// error handling: Count if there are errors while setting the attribs.
|
||||
// if there were any, return an error.
|
||||
var (
|
||||
xerrs = 0
|
||||
xerr error
|
||||
)
|
||||
b.metrics.writes.Inc()
|
||||
for key, val := range attribs {
|
||||
if xerr = xattr.Set(path, key, val); xerr != nil {
|
||||
// log
|
||||
xerrs++
|
||||
}
|
||||
}
|
||||
if xerrs > 0 {
|
||||
return errors.Wrap(xerr, "Failed to set all xattrs")
|
||||
}
|
||||
|
||||
attribs, err = b.getAll(ctx, n, true, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.metaCache.PushToCache(b.cacheKey(n), attribs)
|
||||
}
|
||||
|
||||
// Remove an extended attribute key
|
||||
func (b XattrsBackend) Remove(ctx context.Context, n MetadataNode, key string) error {
|
||||
path := n.InternalPath()
|
||||
if !n.LockHeld() {
|
||||
lockedFile, err := lockFile(n, path+filelocks.LockFileSuffix, os.O_CREATE|os.O_WRONLY, b.metrics)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.SetLockHeld(true)
|
||||
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
|
||||
defer func() {
|
||||
n.SetLockHeld(false)
|
||||
_ = lockedFile.Close()
|
||||
}()
|
||||
}
|
||||
|
||||
b.metrics.writes.Inc()
|
||||
err := xattr.Remove(path, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
attribs, err := b.getAll(ctx, n, true, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.metaCache.PushToCache(b.cacheKey(n), attribs)
|
||||
}
|
||||
|
||||
// IsMetaFile returns whether the given path represents a meta file
|
||||
func (XattrsBackend) IsMetaFile(path string) bool { return strings.HasSuffix(path, ".meta.lock") }
|
||||
|
||||
// Purge purges the data of a given path
|
||||
func (b XattrsBackend) Purge(ctx context.Context, n MetadataNode) error {
|
||||
path := n.InternalPath()
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
attribs, err := b.getAll(ctx, n, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.metrics.writes.Inc()
|
||||
for attr := range attribs {
|
||||
if strings.HasPrefix(attr, prefixes.OcPrefix) {
|
||||
err := xattr.Remove(path, attr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b.metaCache.RemoveMetadata(b.cacheKey(n))
|
||||
}
|
||||
|
||||
// Rename moves the data for a given path to a new path
|
||||
func (b XattrsBackend) Rename(oldNode, newNode MetadataNode) error {
|
||||
data := map[string][]byte{}
|
||||
err := b.metaCache.PullFromCache(b.cacheKey(oldNode), &data)
|
||||
if err == nil {
|
||||
err = b.metaCache.PushToCache(b.cacheKey(newNode), data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return b.metaCache.RemoveMetadata(b.cacheKey(oldNode))
|
||||
}
|
||||
|
||||
// MetadataPath returns the path of the file holding the metadata for the given path
|
||||
func (XattrsBackend) MetadataPath(n MetadataNode) string { return n.InternalPath() }
|
||||
|
||||
// LockfilePath returns the path of the lock file
|
||||
func (XattrsBackend) LockfilePath(n MetadataNode) string { return n.InternalPath() + ".mlock" }
|
||||
|
||||
// Lock locks the metadata for the given path
|
||||
func (b XattrsBackend) Lock(n MetadataNode) (UnlockFunc, error) {
|
||||
if n.LockHeld() {
|
||||
return func() error { return nil }, nil
|
||||
}
|
||||
|
||||
metaLockPath := b.LockfilePath(n)
|
||||
mlock, err := lockFile(n, metaLockPath, os.O_RDWR|os.O_CREATE, b.metrics)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
n.SetLockHeld(true)
|
||||
return func() error {
|
||||
n.SetLockHeld(false)
|
||||
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
|
||||
return mlock.Close()
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b XattrsBackend) cacheKey(n MetadataNode) string {
|
||||
// rootPath is guaranteed to have no trailing slash
|
||||
// the cache key shouldn't begin with a slash as some stores drop it which can cause
|
||||
// confusion
|
||||
return n.GetSpaceID() + "/" + n.GetID()
|
||||
}
|
||||
Generated
Vendored
+1
-1
@@ -39,7 +39,7 @@ type Options struct {
|
||||
// the gateway address
|
||||
GatewayAddr string `mapstructure:"gateway_addr"`
|
||||
|
||||
// the metadata backend to use, currently supports `xattr` or `ini`
|
||||
// the metadata backend to use, currently only supports 'messagepack' (default).
|
||||
MetadataBackend string `mapstructure:"metadata_backend"`
|
||||
|
||||
// the attribute key prefix of the metadata on disk, process wide, see prefixes.SetOcPrefix
|
||||
|
||||
Generated
Vendored
+24
-4
@@ -84,8 +84,13 @@ func (p Permissions) SetSpaceQuota(ctx context.Context, spaceid string, spaceTyp
|
||||
}
|
||||
|
||||
// ManageSpaceProperties returns true when the user is allowed to change space properties (name/subtitle)
|
||||
func (p Permissions) ManageSpaceProperties(ctx context.Context, spaceid string) bool {
|
||||
return p.checkPermission(ctx, "Drives.ReadWrite", spaceRef(spaceid))
|
||||
func (p Permissions) ManageSpaceProperties(ctx context.Context, spaceid string, spaceType string) bool {
|
||||
switch spaceType {
|
||||
case _spaceTypePersonal:
|
||||
return p.checkPermission(ctx, "Drives.ReadWritePersonal", spaceRef(spaceid))
|
||||
default:
|
||||
return p.checkPermission(ctx, "Drives.ReadWrite", spaceRef(spaceid))
|
||||
}
|
||||
}
|
||||
|
||||
// SpaceAbility returns true when the user is allowed to enable/disable the space
|
||||
@@ -93,11 +98,26 @@ func (p Permissions) SpaceAbility(ctx context.Context, spaceid string) bool {
|
||||
return p.checkPermission(ctx, "Drives.ReadWriteEnabled", spaceRef(spaceid))
|
||||
}
|
||||
|
||||
// ListAllSpaces returns true when the user is allowed to list all spaces
|
||||
// RestoreSpace returns true when the user is allowed to restore a disabled space
|
||||
func (p Permissions) RestoreSpace(ctx context.Context, spaceid string, spaceType string) bool {
|
||||
switch spaceType {
|
||||
case _spaceTypePersonal:
|
||||
return p.DeleteAllHomeSpaces(ctx)
|
||||
default:
|
||||
return p.SpaceAbility(ctx, spaceid)
|
||||
}
|
||||
}
|
||||
|
||||
// ListAllSpaces returns true when the user is allowed to list all project spaces
|
||||
func (p Permissions) ListAllSpaces(ctx context.Context) bool {
|
||||
return p.checkPermission(ctx, "Drives.List", nil)
|
||||
}
|
||||
|
||||
// ListAllPersonalSpaces returns true when the user is allowed to list all personal spaces
|
||||
func (p Permissions) ListAllPersonalSpaces(ctx context.Context) bool {
|
||||
return p.checkPermission(ctx, "Drives.ListPersonal", nil)
|
||||
}
|
||||
|
||||
// ListSpacesOfUser returns true when the user is allowed to list the spaces of the given user
|
||||
func (p Permissions) ListSpacesOfUser(ctx context.Context, userid *userv1beta1.UserId) bool {
|
||||
switch {
|
||||
@@ -107,7 +127,7 @@ func (p Permissions) ListSpacesOfUser(ctx context.Context, userid *userv1beta1.U
|
||||
case utils.UserIDEqual(ctxpkg.ContextMustGetUser(ctx).GetId(), userid):
|
||||
return true
|
||||
default:
|
||||
return p.ListAllSpaces(ctx)
|
||||
return p.ListAllSpaces(ctx) || p.ListAllPersonalSpaces(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
Vendored
+12
@@ -175,6 +175,7 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
|
||||
versionNode *node.BaseNode
|
||||
oldAttrs node.Attributes
|
||||
oldMtime time.Time
|
||||
obsoleteBlobID string
|
||||
)
|
||||
|
||||
defer func() {
|
||||
@@ -289,6 +290,13 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
|
||||
}
|
||||
}
|
||||
|
||||
// Without a revision the old blob has no reference left once the node points to
|
||||
// the new one. A revision kept only for a rollback holds it until its removal.
|
||||
// On posix the blob is the file itself, which the new content replaces.
|
||||
if fs.o.DisableVersioning && fs.separateBlobs && overwrite && !versionCreated && old.BlobID != sessionID {
|
||||
obsoleteBlobID = old.BlobID
|
||||
}
|
||||
|
||||
sizeDiff = info.Size - old.Blobsize
|
||||
} else {
|
||||
// InitNewNode has cached a node it created
|
||||
@@ -351,9 +359,13 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
|
||||
// and their blobs are deleted with them.
|
||||
n.BlobID = sessionID
|
||||
fs.removeRevisions(ctx, n)
|
||||
fs.deleteObsoleteBlob(ctx, n, obsoleteBlobID)
|
||||
}
|
||||
|
||||
result := &storage.PrepareUploadResult{VersionCreated: versionCreated, SizeDiff: sizeDiff, Committed: inline}
|
||||
if !inline {
|
||||
result.ObsoleteBlobID = obsoleteBlobID
|
||||
}
|
||||
if !info.NodeExisted {
|
||||
// read off the disk, not through ListGrants: an uploader who cannot see the
|
||||
// space root still needs the manager of a project space reported
|
||||
|
||||
+72
-33
@@ -311,7 +311,8 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
|
||||
return nil, errtypes.PermissionDenied(fmt.Sprintf("user %s is not allowed to list spaces of other users", authenticatedUserID))
|
||||
}
|
||||
|
||||
checkNodePermissions := fs.MustCheckNodePermissions(ctx, unrestricted)
|
||||
checkProjectNodePermissions := fs.MustCheckNodePermissions(ctx, unrestricted)
|
||||
checkPersonalNodePermissions := fs.mustCheckPersonalNodePermissions(ctx, unrestricted)
|
||||
|
||||
spaces := []*provider.StorageSpace{}
|
||||
// build the glob path, eg.
|
||||
@@ -330,7 +331,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
|
||||
// return empty list
|
||||
return spaces, nil
|
||||
}
|
||||
space, err := fs.StorageSpaceFromNode(ctx, n, checkNodePermissions)
|
||||
space, err := fs.storageSpaceFromNode(ctx, n, checkProjectNodePermissions, checkPersonalNodePermissions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -484,7 +485,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
|
||||
continue
|
||||
}
|
||||
|
||||
space, err := fs.StorageSpaceFromNode(ctx, n, checkNodePermissions)
|
||||
space, err := fs.storageSpaceFromNode(ctx, n, checkProjectNodePermissions, checkPersonalNodePermissions)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case errtypes.IsPermissionDenied:
|
||||
@@ -549,7 +550,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
|
||||
return nil, err
|
||||
}
|
||||
if n.Exists {
|
||||
space, err := fs.StorageSpaceFromNode(ctx, n, checkNodePermissions)
|
||||
space, err := fs.storageSpaceFromNode(ctx, n, checkProjectNodePermissions, checkPersonalNodePermissions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -588,17 +589,45 @@ func (fs *Decomposedfs) UserIDToUserAndGroups(ctx context.Context, userid *userv
|
||||
// MustCheckNodePermissions checks if permission checks are needed to be performed when user requests spaces
|
||||
func (fs *Decomposedfs) MustCheckNodePermissions(ctx context.Context, unrestricted bool) bool {
|
||||
// canListAllSpaces indicates if the user has the permission from the global user role
|
||||
canListAllSpaces := fs.p.ListAllSpaces(ctx)
|
||||
// and requests all spaces
|
||||
canListAllSpaces := unrestricted && fs.p.ListAllSpaces(ctx)
|
||||
// unrestricted is the param which indicates if the user wants to list all spaces or only the spaces he is part of
|
||||
// if a user lists all spaces unrestricted and doesn't have the permissions from the role, we need to check
|
||||
// the nodePermissions and this will return a spaces list where the user has access to
|
||||
// we can only skip the NodePermissions check if both values are true
|
||||
if canListAllSpaces && unrestricted {
|
||||
if canListAllSpaces {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// canListAllSpaces returns true when the user is allowed to list all spaces of the given node's type
|
||||
func (fs *Decomposedfs) canListAllSpaces(ctx context.Context, n *node.Node) bool {
|
||||
if n.SpaceRoot == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
spaceType, err := n.SpaceRoot.XattrString(ctx, prefixes.SpaceTypeAttr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if spaceType == _spaceTypePersonal {
|
||||
return fs.p.ListAllPersonalSpaces(ctx)
|
||||
}
|
||||
|
||||
return fs.p.ListAllSpaces(ctx)
|
||||
}
|
||||
|
||||
// mustCheckPersonalNodePermissions is the Drives.ListPersonal counterpart of MustCheckNodePermissions.
|
||||
func (fs *Decomposedfs) mustCheckPersonalNodePermissions(ctx context.Context, unrestricted bool) bool {
|
||||
if unrestricted && fs.p.ListAllPersonalSpaces(ctx) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// UpdateStorageSpace updates a storage space
|
||||
func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
|
||||
var restore bool
|
||||
@@ -670,6 +699,13 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
|
||||
}, nil
|
||||
}
|
||||
|
||||
spaceType, err := spaceNode.SpaceRoot.XattrString(ctx, prefixes.SpaceTypeAttr)
|
||||
if err != nil {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_INTERNAL, Message: "space has no type"},
|
||||
}, nil
|
||||
}
|
||||
|
||||
sp, err := fs.p.AssemblePermissions(ctx, spaceNode)
|
||||
if err != nil {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
@@ -693,31 +729,25 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
|
||||
k = append(k, prefixes.SpaceReadmeAttr, prefixes.SpaceAliasAttr, prefixes.SpaceImageAttr)
|
||||
}
|
||||
|
||||
if mapHasKey(metadata, k...) && !fs.p.ManageSpaceProperties(ctx, spaceID) {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
|
||||
}, nil
|
||||
if mapHasKey(metadata, k...) {
|
||||
if !fs.p.ManageSpaceProperties(ctx, spaceID, spaceType) {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
if restore && !fs.p.SpaceAbility(ctx, spaceID) {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_NOT_FOUND},
|
||||
}, nil
|
||||
if restore {
|
||||
if !fs.p.RestoreSpace(ctx, spaceID, spaceType) {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_NOT_FOUND},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if mapHasKey(metadata, prefixes.QuotaAttr) {
|
||||
typ, err := spaceNode.SpaceRoot.Xattr(ctx, prefixes.SpaceTypeAttr)
|
||||
if err != nil {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{
|
||||
Code: v1beta11.Code_CODE_INTERNAL,
|
||||
Message: "space has no type",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
if !fs.p.SetSpaceQuota(ctx, spaceID, string(typ)) {
|
||||
if !fs.p.SetSpaceQuota(ctx, spaceID, spaceType) {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
|
||||
}, nil
|
||||
@@ -1000,7 +1030,22 @@ func (fs *Decomposedfs) linkStorageSpaceType(ctx context.Context, spaceType, spa
|
||||
}
|
||||
|
||||
func (fs *Decomposedfs) StorageSpaceFromNode(ctx context.Context, n *node.Node, checkPermissions bool) (*provider.StorageSpace, error) {
|
||||
return fs.storageSpaceFromNode(ctx, n, checkPermissions, checkPermissions)
|
||||
}
|
||||
|
||||
func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node, checkProjectNodePermissions, checkPersonalNodePermissions bool) (*provider.StorageSpace, error) {
|
||||
user := ctxpkg.ContextMustGetUser(ctx)
|
||||
|
||||
spaceType, err := n.SpaceRoot.XattrString(ctx, prefixes.SpaceTypeAttr)
|
||||
if err != nil {
|
||||
return nil, errtypes.InternalError(fmt.Sprintf("space %s does not have a type attribute", n.GetID()))
|
||||
}
|
||||
|
||||
checkPermissions := checkProjectNodePermissions
|
||||
if spaceType == _spaceTypePersonal {
|
||||
checkPermissions = checkPersonalNodePermissions
|
||||
}
|
||||
|
||||
if checkPermissions {
|
||||
rp, err := fs.p.AssemblePermissions(ctx, n)
|
||||
switch {
|
||||
@@ -1020,7 +1065,6 @@ func (fs *Decomposedfs) StorageSpaceFromNode(ctx context.Context, n *node.Node,
|
||||
|
||||
sublog := appctx.GetLogger(ctx).With().Str("spaceid", n.GetSpaceID()).Logger()
|
||||
|
||||
var err error
|
||||
// TODO apply more filters
|
||||
var sname string
|
||||
if sname, err = n.SpaceRoot.XattrString(ctx, prefixes.SpaceNameAttr); err != nil {
|
||||
@@ -1145,16 +1189,11 @@ func (fs *Decomposedfs) StorageSpaceFromNode(ctx context.Context, n *node.Node,
|
||||
SpaceId: n.SpaceRoot.GetSpaceID(),
|
||||
OpaqueId: n.SpaceRoot.GetID(),
|
||||
},
|
||||
Name: sname,
|
||||
// SpaceType is read from xattr below
|
||||
Name: sname,
|
||||
SpaceType: spaceType,
|
||||
// Mtime is set either as node.tmtime or as fi.mtime below
|
||||
}
|
||||
|
||||
space.SpaceType, err = n.SpaceRoot.XattrString(ctx, prefixes.SpaceTypeAttr)
|
||||
if err != nil {
|
||||
appctx.GetLogger(ctx).Debug().Err(err).Msg("space does not have a type attribute")
|
||||
}
|
||||
|
||||
if n.SpaceRoot.IsDisabled(ctx) {
|
||||
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "trashed", "trashed")
|
||||
}
|
||||
|
||||
+9
@@ -73,6 +73,10 @@ type PrepareUploadResult struct {
|
||||
// Committed reports that PrepareUpload stored UploadInfo.Source: the upload
|
||||
// is complete, and neither CommitUpload nor MarkProcessing must follow.
|
||||
Committed bool
|
||||
// ObsoleteBlobID is the blob the node pointed to before this upload and
|
||||
// that nothing else references. The driver deletes it once the new content
|
||||
// is stored; the coordinator hands it back in UploadSource. Empty when none.
|
||||
ObsoleteBlobID string
|
||||
}
|
||||
|
||||
// RollbackInfo carries what a driver needs to undo PrepareUpload. NodeID and
|
||||
@@ -275,6 +279,11 @@ type UploadSource struct {
|
||||
// place instead of copying Body; the file is gone after a successful commit.
|
||||
Path string
|
||||
|
||||
// ObsoleteBlobID is the blob the node pointed to before this upload and
|
||||
// that nothing else references. The driver deletes it once the new content
|
||||
// is stored. Empty when none.
|
||||
ObsoleteBlobID string
|
||||
|
||||
// ScanResult is the antivirus verdict: empty means clean.
|
||||
ScanResult string
|
||||
// ScanDate is zero when the upload was not scanned.
|
||||
|
||||
+7
-5
@@ -448,6 +448,7 @@ func (c *coordinator) prepare(ctx context.Context, session Session, info storage
|
||||
}
|
||||
session.SetSizeDiff(prepared.SizeDiff)
|
||||
session.SetVersionCreated(prepared.VersionCreated)
|
||||
session.SetObsoleteBlobID(prepared.ObsoleteBlobID)
|
||||
if prepared.Committed {
|
||||
// the upload is complete, the session is about to be removed
|
||||
return true, nil
|
||||
@@ -642,11 +643,12 @@ func (c *coordinator) commit(ctx context.Context, session Session) (*provider.Re
|
||||
// CommitUpload does not own the body; we opened it, so we close it. The path
|
||||
// lets a driver that can move the staged file into place skip the copy.
|
||||
err = c.fs.CommitUpload(ctx, &ref, session.ID(), storage.UploadSource{
|
||||
Body: f,
|
||||
Path: session.BinPath(),
|
||||
Length: session.Size(),
|
||||
ScanResult: scanResult,
|
||||
ScanDate: scanDate,
|
||||
Body: f,
|
||||
Path: session.BinPath(),
|
||||
Length: session.Size(),
|
||||
ObsoleteBlobID: session.ObsoleteBlobID(),
|
||||
ScanResult: scanResult,
|
||||
ScanDate: scanDate,
|
||||
})
|
||||
f.Close()
|
||||
if err != nil {
|
||||
|
||||
+14
@@ -83,6 +83,8 @@ type Session interface {
|
||||
SetSizeDiff(d int64)
|
||||
VersionCreated() bool
|
||||
SetVersionCreated(v bool)
|
||||
ObsoleteBlobID() string
|
||||
SetObsoleteBlobID(id string)
|
||||
Metadata() map[string]string
|
||||
Persist(ctx context.Context) error
|
||||
Cleanup(ctx context.Context, cleanBin, cleanInfo bool)
|
||||
@@ -320,6 +322,18 @@ func (s *FileSession) SetVersionCreated(v bool) {
|
||||
s.info.MetaData["versionCreated"] = strconv.FormatBool(v)
|
||||
}
|
||||
|
||||
// ObsoleteBlobID returns the blob PrepareUpload reported as replaced by this
|
||||
// upload, for the driver to delete once the new content is stored.
|
||||
func (s *FileSession) ObsoleteBlobID() string {
|
||||
return s.info.MetaData["obsoleteBlobID"]
|
||||
}
|
||||
|
||||
// SetObsoleteBlobID records what PrepareUpload reported. Persisted for the same
|
||||
// reason as the size diff: on the async path the commit runs in another process.
|
||||
func (s *FileSession) SetObsoleteBlobID(id string) {
|
||||
s.info.MetaData["obsoleteBlobID"] = id
|
||||
}
|
||||
|
||||
// SetScanData stores AV scan results on the session.
|
||||
func (s *FileSession) SetScanData(result string, date time.Time) {
|
||||
s.info.MetaData["scanResult"] = result
|
||||
|
||||
Vendored
+1
-1
@@ -1360,7 +1360,7 @@ github.com/opencloud-eu/icap-client
|
||||
# github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e
|
||||
## explicit; go 1.23
|
||||
github.com/opencloud-eu/libre-graph-api-go
|
||||
# github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec
|
||||
# github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3
|
||||
## explicit; go 1.26.0
|
||||
github.com/opencloud-eu/reva/v3/cmd/revad/internal/grace
|
||||
github.com/opencloud-eu/reva/v3/cmd/revad/runtime
|
||||
|
||||
Reference in new issue
Block a user