Skip to content

Commit

Permalink
Moved ParseFileMode function from utils to client since it is u…
Browse files Browse the repository at this point in the history
…sed only in `client` file.
  • Loading branch information
sfc-gh-psmolenski committed Nov 15, 2024
1 parent 46f1d2a commit 55a8611
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
15 changes: 12 additions & 3 deletions services/localfile/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io/fs"
"os"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -766,7 +767,7 @@ func (c *chmodCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
return subcommands.ExitFailure
}

mode, err := ParseFileMode(c.mode)
mode, err := parseFileMode(c.mode)

if err != nil {
fmt.Fprintln(os.Stderr, "Invalid --mode '%s'. An octal number expected (e.g. 644, 755, 0777).\n", c.mode)

Check failure on line 773 in services/localfile/client/client.go

View workflow job for this annotation

GitHub Actions / golangci lint

printf: fmt.Fprintln call has possible Printf formatting directive %s (govet)

Check failure on line 773 in services/localfile/client/client.go

View workflow job for this annotation

GitHub Actions / Integration tests

fmt.Fprintln call has possible Printf formatting directive %s

Check failure on line 773 in services/localfile/client/client.go

View workflow job for this annotation

GitHub Actions / Unit tests

fmt.Fprintln call has possible Printf formatting directive %s
Expand Down Expand Up @@ -1066,7 +1067,7 @@ func (p *cpCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{
}
}

mode, err := ParseFileMode(p.mode)
mode, err := parseFileMode(p.mode)

if err != nil {
fmt.Fprintf(os.Stderr, "Invalid --mode '%s'. An octal number expected (e.g. 644, 755, 0777).\n", p.mode)
Expand Down Expand Up @@ -1412,7 +1413,7 @@ func (p *mkdirCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
c := pb.NewLocalFileClientProxy(state.Conn)
directoryName := f.Args()[0]

mode, err := ParseFileMode(p.mode)
mode, err := parseFileMode(p.mode)

if err != nil {
fmt.Fprintf(os.Stderr, "Invalid --mode '%s'. An octal number expected (e.g. 644, 755, 0777).\n", p.mode)
Expand Down Expand Up @@ -1482,3 +1483,11 @@ func (p *mkdirCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
return retCode

}

const fileModeSizeInBits = 12

func parseFileMode(modeStr string) (uint16, error) {
mode, err := strconv.ParseUint(modeStr, 8, fileModeSizeInBits)

return uint16(mode), err
}
9 changes: 0 additions & 9 deletions services/localfile/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"io"
"path/filepath"
"strconv"

"github.com/Snowflake-Labs/sansshell/proxy/proxy"
pb "github.com/Snowflake-Labs/sansshell/services/localfile"
Expand Down Expand Up @@ -578,11 +577,3 @@ func ListRemote(ctx context.Context, conn *proxy.Conn, listRequest ListRequest)
}
return ret, nil
}

const fileModeSizeInBits = 12

func ParseFileMode(modeStr string) (uint16, error) {
mode, err := strconv.ParseUint(modeStr, 8, fileModeSizeInBits)

return uint16(mode), err
}

0 comments on commit 55a8611

Please sign in to comment.