From a2d5ee2bc63a196efadd3fed03dcc2313b393263 Mon Sep 17 00:00:00 2001 From: Alex Ababii Date: Wed, 19 Aug 2026 14:11:48 +0200 Subject: [PATCH] fix revisions purge cli command for posix --- opencloud/pkg/command/revisions.go | 63 ++++++++++++++----- tests/acceptance/docker/src/acceptance.yml | 1 + .../cliCommands/removeFileVersions.feature | 8 +-- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/opencloud/pkg/command/revisions.go b/opencloud/pkg/command/revisions.go index 212388759a..69fcaa44f6 100644 --- a/opencloud/pkg/command/revisions.go +++ b/opencloud/pkg/command/revisions.go @@ -25,6 +25,8 @@ var ( _nodesGlobPattern = "spaces/*/*/nodes/" ) +const posixDriver = "posix" + // RevisionsCommand is the entrypoint for the revisions command. func RevisionsCommand(cfg *config.Config) *cobra.Command { revCmd := &cobra.Command{ @@ -86,23 +88,28 @@ func PurgeRevisionsCommand(cfg *config.Config) *cobra.Command { mechanism = "glob" } + var posix = cfg.StorageUsers.Driver == posixDriver + var ch <-chan string switch mechanism { default: fallthrough case "glob": - p := generatePath(basePath, rid) + p := generatePath(basePath, rid, posix) if rid.GetOpaqueId() == "" { p = filepath.Join(p, "*/*/*/*/*") } ch = revisions.Glob(p) case "workers": - p := generatePath(basePath, rid) + p := generatePath(basePath, rid, posix) ch = revisions.GlobWorkers(p, "/*", "/*/*/*/*") case "list": - p := filepath.Join(basePath, "spaces") + p := basePath + if !posix { + p = filepath.Join(basePath, "spaces") + } if rid != nil { - p = generatePath(basePath, rid) + p = generatePath(basePath, rid, posix) } ch = revisions.List(p, 10) } @@ -144,22 +151,44 @@ func printResults(countFiles, countBlobs, countRevisions int, dryRun bool) { } } -func generatePath(basePath string, rid *provider.ResourceId) string { - if rid == nil { - return filepath.Join(basePath, _nodesGlobPattern) - } +func generatePath(basePath string, rid *provider.ResourceId, posix bool) string { + // decomposedfs and posix store the revisions of a node at different + // locations on disk, so the path has to be built per driver: + // - decomposedfs: /spaces//nodes/.REV. + // - posix: ///.oc-nodes/.REV. + if posix { + if rid == nil { + return filepath.Join(basePath, "*", "*", ".oc-nodes") + } - sid := lookup.Pathify(rid.GetSpaceId(), 1, 2) - if sid == "" { - return "" - } + nid := lookup.Pathify(rid.GetOpaqueId(), 4, 2) + if nid != "" { + return filepath.Join(basePath, "*", "*", ".oc-nodes", nid+"*") + } - nid := lookup.Pathify(rid.GetOpaqueId(), 4, 2) - if nid == "" { - return filepath.Join(basePath, "spaces", sid, "nodes") - } + if rid.GetSpaceId() == "" { + return "" + } + return filepath.Join(basePath, "*", rid.GetSpaceId(), ".oc-nodes") + } else { + // decomposedfs + if rid == nil { - return filepath.Join(basePath, "spaces", sid, "nodes", nid+"*") + return filepath.Join(basePath, _nodesGlobPattern) + } + + sid := lookup.Pathify(rid.GetSpaceId(), 1, 2) + if sid == "" { + return "" + } + + nid := lookup.Pathify(rid.GetOpaqueId(), 4, 2) + if nid == "" { + return filepath.Join(basePath, "spaces", sid, "nodes") + } + + return filepath.Join(basePath, "spaces", sid, "nodes", nid+"*") + } } func init() { diff --git a/tests/acceptance/docker/src/acceptance.yml b/tests/acceptance/docker/src/acceptance.yml index 633d150cd8..57711e9872 100644 --- a/tests/acceptance/docker/src/acceptance.yml +++ b/tests/acceptance/docker/src/acceptance.yml @@ -10,6 +10,7 @@ services: STORAGE_DRIVER: ${STORAGE_DRIVER:-posix} BEHAT_SUITE: ${BEHAT_SUITE:-} BEHAT_FEATURE: ${BEHAT_FEATURE:-} + OC_BASE_DATA_PATH: ${OC_BASE_DATA_PATH:-/var/lib/opencloud} USE_BEARER_TOKEN: ${USE_BEARER_TOKEN:-false} # email EMAIL_HOST: email diff --git a/tests/acceptance/features/cliCommands/removeFileVersions.feature b/tests/acceptance/features/cliCommands/removeFileVersions.feature index 383fadc100..eae75fb677 100644 --- a/tests/acceptance/features/cliCommands/removeFileVersions.feature +++ b/tests/acceptance/features/cliCommands/removeFileVersions.feature @@ -1,4 +1,4 @@ -@env-config @skipOnOpencloud-posix-Storage +@env-config Feature: remove file versions via CLI command Background: @@ -11,7 +11,7 @@ Feature: remove file versions via CLI command And user "Alice" has uploaded file with content "This is version 3" to "textfile.txt" When the administrator removes all the file versions using the CLI Then the command should be successful - And the command output should contain "✅ Deleted 2 revisions (6 files / 2 blobs)" + And the command output should contain "✅ Deleted 2 revisions" When user "Alice" gets the number of versions of file "textfile.txt" Then the HTTP status code should be "207" And the number of versions should be "0" @@ -26,7 +26,7 @@ Feature: remove file versions via CLI command And user "Alice" has uploaded file with content "This is version 3" to "anotherFile.txt" When the administrator removes the versions of file "randomFile.txt" of user "Alice" from space "Personal" using the CLI Then the command should be successful - And the command output should contain "✅ Deleted 2 revisions (6 files / 2 blobs)" + And the command output should contain "✅ Deleted 2 revisions" When user "Alice" gets the number of versions of file "randomFile.txt" Then the HTTP status code should be "207" And the number of versions should be "0" @@ -52,7 +52,7 @@ Feature: remove file versions via CLI command And we save it into "EPSUM_FILEID" When the administrator removes the file versions of space "projectSpace" using the CLI Then the command should be successful - And the command output should contain "✅ Deleted 4 revisions (12 files / 4 blobs)" + And the command output should contain "✅ Deleted 4 revisions" When user "Alice" gets the number of versions of file "file.txt" Then the HTTP status code should be "207" And the number of versions should be "2"