From 559b10e90a21c6928614f62c6ece99585dfe211a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 3 Aug 2026 09:49:10 +0200 Subject: [PATCH] Check if the given path is part of the storage --- opencloud/pkg/command/posixfs.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/opencloud/pkg/command/posixfs.go b/opencloud/pkg/command/posixfs.go index 5b36d7fd93..54e8e688c0 100644 --- a/opencloud/pkg/command/posixfs.go +++ b/opencloud/pkg/command/posixfs.go @@ -188,7 +188,7 @@ The argument determines the scope of the check: - a storage root: the whole storage (all personal and project spaces) is checked - a space root: only that space is checked - a file or folder: only that single entity is checked (and its children, if it is a folder)`, - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), PreRunE: func(cmd *cobra.Command, args []string) error { if err := parser.ParseConfig(ocCfg, true); err != nil { @@ -202,7 +202,11 @@ The argument determines the scope of the check: }, RunE: func(cmd *cobra.Command, args []string) error { cfg := ocCfg.StorageUsers - return checkPosixfsConsistency(cfg, cmd, args[0]) + path := cfg.Drivers.Posix.Root + if len(args) > 0 { + path = args[0] + } + return checkPosixfsConsistency(cfg, cmd, path) }, } consCmd.Flags().Bool("fix-checksums", false, "Recalculate and fix the file checksums. This reads every file and can be slow on large storages.") @@ -235,6 +239,7 @@ func checkPosixfsConsistency(cfg *storageUsersConfig.Config, cmd *cobra.Command, } ignorer = ignore.NewIgnorer(opts, &log) + contained, _ := filepathx.IsSameOrContainedBy(rootPath, path) switch { case path == rootPath: @@ -246,9 +251,11 @@ func checkPosixfsConsistency(cfg *storageUsersConfig.Config, cmd *cobra.Command, case isSpaceRoot(path): fmt.Printf("Checking space '%s'...\n", path) checkSpace(path) - default: + case contained: fmt.Printf("Checking '%s'...\n", path) checkEntity(path) + default: + return fmt.Errorf("the provided path '%s' is neither a space root nor contained by the storage root '%s'", path, rootPath) } if restartRequired {