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

Storage list for lens #2852

Merged
merged 2 commits into from
May 22, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog for NeoFS Node
## [Unreleased]

### Added
- "storage list" command to neofs-lens (#2852)

### Fixed

Expand Down
48 changes: 48 additions & 0 deletions cmd/neofs-lens/internal/storage/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package storage

import (
"errors"
"io"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
"github.com/spf13/cobra"
)

var storageListObjsCMD = &cobra.Command{
Use: "list",
Short: "Object listing",
Long: `List all objects stored in a blobstor (as registered in metabase).`,
Args: cobra.NoArgs,
Run: listFunc,
}

func init() {
common.AddConfigFileFlag(storageListObjsCMD, &vConfig)

Check warning on line 21 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L20-L21

Added lines #L20 - L21 were not covered by tests
}

func listFunc(cmd *cobra.Command, _ []string) {

Check warning on line 24 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L24

Added line #L24 was not covered by tests
// other targets can be supported
w := cmd.OutOrStderr()

Check warning on line 26 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L26

Added line #L26 was not covered by tests

storage := openEngine(cmd)
defer storage.Close()

Check warning on line 29 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L28-L29

Added lines #L28 - L29 were not covered by tests

var p engine.ListWithCursorPrm
p.WithCount(1024)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic? can lose 1025-th object and do not understand it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will list everything. Yeah, magic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, almost endless for, did not see it. check context b/w iteration then to make it controllable?

for {
r, err := storage.ListWithCursor(p)
if err != nil {
if errors.Is(err, engine.ErrEndOfListing) {
return

Check warning on line 37 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L31-L37

Added lines #L31 - L37 were not covered by tests
}
common.ExitOnErr(cmd, common.Errf("Storage iterator failure: %w", err))

Check warning on line 39 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L39

Added line #L39 was not covered by tests
}
var addrs = r.AddressList()
for _, at := range addrs {
_, err = io.WriteString(w, at.Address.String()+"\n")
common.ExitOnErr(cmd, common.Errf("print failure: %w", err))

Check warning on line 44 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L41-L44

Added lines #L41 - L44 were not covered by tests
}
p.WithCursor(r.Cursor())

Check warning on line 46 in cmd/neofs-lens/internal/storage/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/list.go#L46

Added line #L46 was not covered by tests
}
}
3 changes: 2 additions & 1 deletion cmd/neofs-lens/internal/storage/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@

var Root = &cobra.Command{
Use: "storage",
Short: "Operations with an object",
Short: "Operations with blobstor",
Args: cobra.NoArgs,
}

func init() {
Root.AddCommand(
storageGetObjCMD,
storageListObjsCMD,

Check warning on line 46 in cmd/neofs-lens/internal/storage/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/storage/root.go#L46

Added line #L46 was not covered by tests
storageStatusObjCMD,
)
}
Expand Down
Loading