Skip to content

Commit c3c4080

Browse files
CLI range file improvements (#3544)
2 parents be59b71 + 2056867 commit c3c4080

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Changelog for NeoFS Node
1010

1111
### Changed
1212
- Stream payload without buffering to reduce memory usage in CLI `Get/Put` operations (#3535)
13+
- `neofs-cli object range` command now truncates file passed to `--file` (#3544)
14+
- `neofs-cli object range` command now creates file with `rw-r--r--` permissions (#3544)
1315

1416
### Removed
1517
- `neofs-cli object head --main-only` no-op flag (#3509)

cmd/neofs-cli/modules/object/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func getObject(cmd *cobra.Command, _ []string) error {
5757
if filename == "" {
5858
out = os.Stdout
5959
} else {
60-
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
60+
f, err := openFileForPayload(filename)
6161
if err != nil {
62-
return fmt.Errorf("can't open file '%s': %w", filename, err)
62+
return err
6363
}
6464

6565
defer func() { _ = f.Close() }()

cmd/neofs-cli/modules/object/range.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ func getObjectRange(cmd *cobra.Command, _ []string) error {
6969
if filename == "" {
7070
out = os.Stdout
7171
} else {
72-
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, os.ModePerm)
72+
f, err := openFileForPayload(filename)
7373
if err != nil {
74-
return fmt.Errorf("can't open file '%s': %w", filename, err)
74+
return err
7575
}
7676

7777
defer f.Close()

cmd/neofs-cli/modules/object/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/ecdsa"
66
"errors"
77
"fmt"
8+
"io"
89
"os"
910
"strings"
1011

@@ -361,3 +362,11 @@ func finalizeSession(cmd *cobra.Command, dst SessionPrm, tok *session.Object, ke
361362
func initFlagSession(cmd *cobra.Command, verb string) {
362363
commonflags.InitSession(cmd, "object "+verb)
363364
}
365+
366+
func openFileForPayload(name string) (io.WriteCloser, error) {
367+
f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
368+
if err != nil {
369+
return nil, fmt.Errorf("can't open file '%s': %w", name, err)
370+
}
371+
return f, nil
372+
}

0 commit comments

Comments
 (0)