Skip to content

Commit

Permalink
cmd/uplinkng: refactor into some focused packages
Browse files Browse the repository at this point in the history
the directory was starting to get pretty large and
it was making it hard to pick concise names for
types and variables. this moves the location
stuff into a cmd/uplinkng/ulloc package, the
filesystem stuff into a cmd/uplinkng/ulfs package,
and the testing stuff into a cmd/uplinkng/ultest
package.

this should make the remaining stuff in cmd/uplinkng
only the business logic of how to implement the
commands, rather than also including a bunch of
helper utilities and scaffolding.

Change-Id: Id0901625ebfff9b1cf2dae52366aceb3b6c8f5b6
  • Loading branch information
zeebo committed Jun 14, 2021
1 parent b24ea2e commit 98be54b
Show file tree
Hide file tree
Showing 16 changed files with 844 additions and 703 deletions.
21 changes: 12 additions & 9 deletions cmd/uplinkng/cmd_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
progressbar "github.com/cheggaaa/pb/v3"
"github.com/zeebo/clingy"
"github.com/zeebo/errs"

"storj.io/storj/cmd/uplinkng/ulfs"
"storj.io/storj/cmd/uplinkng/ulloc"
)

type cmdCp struct {
Expand All @@ -19,8 +22,8 @@ type cmdCp struct {
recursive bool
dryrun bool

source Location
dest Location
source ulloc.Location
dest ulloc.Location
}

func (c *cmdCp) Setup(a clingy.Arguments, f clingy.Flags) {
Expand All @@ -34,8 +37,8 @@ func (c *cmdCp) Setup(a clingy.Arguments, f clingy.Flags) {
clingy.Transform(strconv.ParseBool),
).(bool)

c.source = a.New("source", "Source to copy", clingy.Transform(parseLocation)).(Location)
c.dest = a.New("dest", "Desination to copy", clingy.Transform(parseLocation)).(Location)
c.source = a.New("source", "Source to copy", clingy.Transform(ulloc.Parse)).(ulloc.Location)
c.dest = a.New("dest", "Desination to copy", clingy.Transform(ulloc.Parse)).(ulloc.Location)
}

func (c *cmdCp) Execute(ctx clingy.Context) error {
Expand All @@ -51,7 +54,7 @@ func (c *cmdCp) Execute(ctx clingy.Context) error {
return c.copyFile(ctx, fs, c.source, c.dest, true)
}

func (c *cmdCp) copyRecursive(ctx clingy.Context, fs filesystem) error {
func (c *cmdCp) copyRecursive(ctx clingy.Context, fs ulfs.Filesystem) error {
if c.source.Std() || c.dest.Std() {
return errs.New("cannot recursively copy to stdin/stdout")
}
Expand Down Expand Up @@ -86,7 +89,7 @@ func (c *cmdCp) copyRecursive(ctx clingy.Context, fs filesystem) error {
return nil
}

func (c *cmdCp) copyFile(ctx clingy.Context, fs filesystem, source, dest Location, progress bool) error {
func (c *cmdCp) copyFile(ctx clingy.Context, fs ulfs.Filesystem, source, dest ulloc.Location, progress bool) error {
if isDir := fs.IsLocalDir(ctx, dest); isDir {
base, ok := source.Base()
if !ok {
Expand Down Expand Up @@ -131,11 +134,11 @@ func (c *cmdCp) copyFile(ctx clingy.Context, fs filesystem, source, dest Locatio
return errs.Wrap(wh.Commit())
}

func copyVerb(source, dest Location) string {
func copyVerb(source, dest ulloc.Location) string {
switch {
case dest.remote:
case dest.Remote():
return "upload"
case source.remote:
case source.Remote():
return "download"
default:
return "copy"
Expand Down
13 changes: 8 additions & 5 deletions cmd/uplinkng/cmd_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"time"

"github.com/zeebo/clingy"

"storj.io/storj/cmd/uplinkng/ulfs"
"storj.io/storj/cmd/uplinkng/ulloc"
)

type cmdLs struct {
Expand All @@ -18,7 +21,7 @@ type cmdLs struct {
pending bool
utc bool

prefix *Location
prefix *ulloc.Location
}

func (c *cmdLs) Setup(a clingy.Arguments, f clingy.Flags) {
Expand All @@ -39,8 +42,8 @@ func (c *cmdLs) Setup(a clingy.Arguments, f clingy.Flags) {
).(bool)

c.prefix = a.New("prefix", "Prefix to list (sj://BUCKET[/KEY])", clingy.Optional,
clingy.Transform(parseLocation),
).(*Location)
clingy.Transform(ulloc.Parse),
).(*ulloc.Location)
}

func (c *cmdLs) Execute(ctx clingy.Context) error {
Expand Down Expand Up @@ -68,7 +71,7 @@ func (c *cmdLs) listBuckets(ctx clingy.Context) error {
return iter.Err()
}

func (c *cmdLs) listLocation(ctx clingy.Context, prefix Location) error {
func (c *cmdLs) listLocation(ctx clingy.Context, prefix ulloc.Location) error {
fs, err := c.OpenFilesystem(ctx, bypassEncryption(c.encrypted))
if err != nil {
return err
Expand All @@ -79,7 +82,7 @@ func (c *cmdLs) listLocation(ctx clingy.Context, prefix Location) error {
defer tw.Done()

// create the object iterator of either existing objects or pending multipart uploads
var iter objectIterator
var iter ulfs.ObjectIterator
if c.pending {
iter, err = fs.ListUploads(ctx, prefix, c.recursive)
} else {
Expand Down
Loading

0 comments on commit 98be54b

Please sign in to comment.