Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Mar 8, 2022
1 parent 71b6cbb commit 40f7f00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
8 changes: 4 additions & 4 deletions pkg/storage/utils/decomposedfs/recycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("Recycle", func() {
When("a user deletes files from the same space", func() {

BeforeEach(func() {
// in this scenario user "u-s-e-r-id" has this permissions:
// in this scenario user "25b69780-5f39-43be-a7ac-a9b9e9fe4230" has this permissions:
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
Expand Down Expand Up @@ -132,7 +132,7 @@ var _ = Describe("Recycle", func() {
Username: "anotherusername",
})

// in this scenario user "u-s-e-r-id" has this permissions:
// in this scenario user "25b69780-5f39-43be-a7ac-a9b9e9fe4230" has this permissions:
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
Expand Down Expand Up @@ -245,7 +245,7 @@ var _ = Describe("Recycle", func() {
Expect(err).ToNot(HaveOccurred())
Expect(projectID).ToNot(BeNil())

// in this scenario user "u-s-e-r-id" has this permissions:
// in this scenario user "25b69780-5f39-43be-a7ac-a9b9e9fe4230" has this permissions:
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
Expand Down Expand Up @@ -317,7 +317,7 @@ var _ = Describe("Recycle", func() {
Username: "readusername",
})

// in this scenario user "u-s-e-r-id" has this permissions:
// in this scenario user "25b69780-5f39-43be-a7ac-a9b9e9fe4230" has this permissions:
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
Delete: true,
ListRecycle: true,
Expand Down
60 changes: 22 additions & 38 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,20 +428,20 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
metadata[xattrs.SpaceDescriptionAttr] = string(description.Value)
hasDescription = true
}
if alias, ok := space.Opaque.Map["spaceAlias"]; ok {
metadata[xattrs.SpaceAliasAttr] = string(alias.Value)
if alias := utils.ReadPlainFromOpaque(space.Opaque, "spaceAlias"); alias != "" {
metadata[xattrs.SpaceAliasAttr] = alias
}
if image, ok := space.Opaque.Map["image"]; ok {
imageID := resourceid.OwnCloudResourceIDUnwrap(string(image.Value))
if image := utils.ReadPlainFromOpaque(space.Opaque, "image"); image != "" {
imageID := resourceid.OwnCloudResourceIDUnwrap(image)
if imageID == nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_NOT_FOUND, Message: "decomposedFS: space image resource not found"},
}, nil
}
metadata[xattrs.SpaceImageAttr] = imageID.OpaqueId
}
if readme, ok := space.Opaque.Map["readme"]; ok {
readmeID := resourceid.OwnCloudResourceIDUnwrap(string(readme.Value))
if readme := utils.ReadPlainFromOpaque(space.Opaque, "readme"); readme != "" {
readmeID := resourceid.OwnCloudResourceIDUnwrap(readme)
if readmeID == nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_NOT_FOUND, Message: "decomposedFS: space readme resource not found"},
Expand Down Expand Up @@ -632,15 +632,18 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
// Mtime is set either as node.tmtime or as fi.mtime below
}

if space.SpaceType, err = n.SpaceRoot.GetMetadata(xattrs.SpaceTypeAttr); err != nil {
spaceAttributes, err := xattrs.All(nodePath)
if err != nil {
return nil, err
}

var hasType bool
if space.SpaceType, hasType = spaceAttributes[xattrs.SpaceTypeAttr]; !hasType {
appctx.GetLogger(ctx).Debug().Err(err).Msg("space does not have a type attribute")
}

if n.SpaceRoot.IsDisabled() {
space.Opaque.Map["trashed"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte("trashed"),
}
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "trashed", "trashed")
}

if n.Owner() != nil && n.Owner().OpaqueId != "" {
Expand Down Expand Up @@ -678,11 +681,6 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
Value: []byte(etag),
}

spaceAttributes, err := xattrs.All(nodePath)
if err != nil {
return nil, err
}

// quota
quotaAttr, ok := spaceAttributes[xattrs.QuotaAttr]
if ok {
Expand All @@ -702,37 +700,23 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
}
spaceImage, ok := spaceAttributes[xattrs.SpaceImageAttr]
if ok {
space.Opaque = utils.AppendPlainToOpaque(
space.Opaque,
"image",
resourceid.OwnCloudResourceIDWrap(
&provider.ResourceId{
StorageId: space.Root.StorageId,
OpaqueId: spaceImage,
},
),
)
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "image", resourceid.OwnCloudResourceIDWrap(
&provider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: spaceImage},
))
}
spaceDescription, ok := spaceAttributes[xattrs.SpaceDescriptionAttr]
if ok {
space.Opaque.Map["description"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(spaceDescription),
}
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "description", spaceDescription)
}
spaceReadme, ok := spaceAttributes[xattrs.SpaceReadmeAttr]
if ok {
space.Opaque.Map["readme"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(resourceid.OwnCloudResourceIDWrap(&provider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: spaceReadme})),
}
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "readme", resourceid.OwnCloudResourceIDWrap(
&provider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: spaceReadme},
))
}
spaceAlias, ok := spaceAttributes[xattrs.SpaceAliasAttr]
if ok {
space.Opaque.Map["spaceAlias"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(spaceAlias),
}
space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "spaceAlias", spaceAlias)
}
return space, nil
}
Expand Down

0 comments on commit 40f7f00

Please sign in to comment.