Skip to content

Commit

Permalink
Lint issues fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Unic-X committed Sep 2, 2024
1 parent ad158bc commit 59d41a5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ go mod tidy
echo "Running tests..."
go test -v ./...

echo "------------Running golangcli-lint---------------"
echo "Running GoLint"
golangci-lint run
LINT_EXIT_CODE=$?

if [ $LINT_EXIT_CODE -ne 0 ]; then
echo "Error During Linting. Fix the issues"
exit $LINT_EXIT_CODE
fi

echo "------------All tests passed successfully---------------"

echo "Building the project"
Expand Down
9 changes: 7 additions & 2 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func StartClient(cmd *cobra.Command, args []string) {
log.Fatalf("Failed to connect to server: %v", err)
}
defer c.Close()
client.Upload(c, clientArgs.f)
err = client.Upload(c, clientArgs.f)
if err != nil {
log.Fatalf("Failed to upload the file to the server %v", err)
}
}

func init() {
Expand All @@ -38,5 +41,7 @@ func init() {
clientCmd.Flags().StringVarP(&clientArgs.password, "password", "p", "password", "password")
clientCmd.Flags().StringVarP(&clientArgs.host, "host", "H", "127.0.0.1:2022", "host address")
clientCmd.Flags().StringVarP(&clientArgs.f, "filepath", "f", "", "file path")
clientCmd.MarkFlagRequired("filepath")
if clientCmd.MarkFlagRequired("filepath") != nil {
log.Fatalf("Required flag -f is missing")
}
}
12 changes: 9 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func Listen(s SFTPServer) {

for newChannel := range chans {
if newChannel.ChannelType() != "session" {
newChannel.Reject(ssh.UnknownChannelType, "unknown channel type")
if newChannel.Reject(ssh.UnknownChannelType, "unknown channel type") != nil {
log.Printf("Error while rejecting channel creation")
}
continue
}

Expand All @@ -87,10 +89,14 @@ func Listen(s SFTPServer) {
go func(in <-chan *ssh.Request) {
for req := range in {
if req.Type == "subsystem" && string(req.Payload[4:]) == "sftp" {
req.Reply(true, nil)
if req.Reply(true, nil) != nil {
log.Printf("Cannot send Reply to the request")
}
handleSFTP(channel)
} else {
req.Reply(false, nil)
if req.Reply(false, nil) != nil {
log.Printf("Cannot send Reply to the request")
}
}
}
}(requests)
Expand Down
12 changes: 5 additions & 7 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ func TestKey(t *testing.T) {
}
}


// Test the listen function
func TestListen(t *testing.T){
func TestListen(t *testing.T) {
s := New("0.0.0.0", "../private/id_rsa", 2022)
go Listen(s)
time.Sleep(1*time.Second)
conn, err := net.Dial("tcp", "127.0.0.1:2022")
if err != nil {
go Listen(s)
time.Sleep(1 * time.Second)
conn, err := net.Dial("tcp", "127.0.0.1:2022")
if err != nil {
t.Fatalf("Failed to connect to the SFTP server: %v", err)
}
conn.Close()

t.Log("SFTP server started and accepted connections successfully")


}
6 changes: 5 additions & 1 deletion utils/chunking.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"hash/fnv"
"io"
"log"
"os"
"time"

Expand Down Expand Up @@ -55,7 +56,10 @@ func ChunkFile(filename string) (File, error) {
}
// instead we should return the slices of file into a buffer
buffer := make([]byte, chunk)
file.ReadAt(buffer, int64(size))
_, err = file.ReadAt(buffer, int64(size))
if err != nil {
log.Printf("Error while reading the bytes of the file %v", err)
}
size += chunk
chunk_buffer = append(chunk_buffer, buffer)
}
Expand Down

0 comments on commit 59d41a5

Please sign in to comment.