Skip to content

Commit c4eb2f6

Browse files
committed
Reduce code complexity to check for trailing separator
Signed-off-by: Peter Verraedt <peter@verraedt.be>
1 parent 3b023b0 commit c4eb2f6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cmd/iron/cli/commands.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (a *App) upload() *cobra.Command { //nolint:funlen
427427
source := filepath.Clean(args[0])
428428
target := a.Path(args[1])
429429

430-
if strings.HasSuffix(args[1], "/") && !strings.HasSuffix(args[0], "/") && !strings.HasSuffix(args[0], string(os.PathSeparator)) {
430+
if strings.HasSuffix(args[1], "/") && !localPathEndsWithSeparator(args[0]) {
431431
target = a.Path(args[1] + filepath.Base(source))
432432
}
433433

@@ -506,7 +506,7 @@ func (a *App) download() *cobra.Command { //nolint:funlen
506506
source := a.Path(args[0])
507507
target := filepath.Clean(args[1])
508508

509-
if (strings.HasSuffix(args[1], "/") || strings.HasSuffix(args[1], string(os.PathSeparator))) && !strings.HasSuffix(args[0], "/") {
509+
if localPathEndsWithSeparator(args[1]) && !strings.HasSuffix(args[0], "/") {
510510
target = filepath.Join(target, Name(source))
511511
}
512512

@@ -523,7 +523,7 @@ func (a *App) download() *cobra.Command { //nolint:funlen
523523
return a.Download(cmd.Context(), target, source, opts)
524524
}
525525

526-
if !strings.HasSuffix(args[1], "/") && !strings.HasSuffix(args[1], string(os.PathSeparator)) {
526+
if !localPathEndsWithSeparator(args[1]) {
527527
return ErrAmbiguousTarget
528528
}
529529

@@ -539,6 +539,10 @@ func (a *App) download() *cobra.Command { //nolint:funlen
539539
return cmd
540540
}
541541

542+
func localPathEndsWithSeparator(path string) bool {
543+
return strings.HasSuffix(path, "/") || strings.HasSuffix(path, string(os.PathSeparator))
544+
}
545+
542546
func (a *App) cat() *cobra.Command {
543547
var maxThreads int
544548

0 commit comments

Comments
 (0)