Przeglądaj źródła

Change file Size type from int to int64 and add test for it

Vahid Sohrabloo 8 lat temu
rodzic
commit
468423d44a
2 zmienionych plików z 15 dodań i 2 usunięć
  1. 13 0
      client_test.go
  2. 2 2
      ftp.go

+ 13 - 0
client_test.go

@@ -96,6 +96,19 @@ func testConn(t *testing.T, disableEPSV bool) {
 		r.Close()
 	}
 
+	fileSize, err := c.FileSize("tset")
+	if err != nil {
+		t.Error(err)
+	}
+	if fileSize != 14 {
+		t.Errorf("file size %q, expected %q", fileSize, 14)
+	}
+
+	fileSize, err = c.FileSize("not-found")
+	if err == nil {
+		t.Fatal("expected error, got nil")
+	}
+
 	err = c.Delete("tset")
 	if err != nil {
 		t.Error(err)

+ 2 - 2
ftp.go

@@ -408,13 +408,13 @@ func (c *ServerConn) CurrentDir() (string, error) {
 }
 
 // FileSize issues a SIZE FTP command, which Returns the size of the file
-func (c *ServerConn) FileSize(path string) (int, error) {
+func (c *ServerConn) FileSize(path string) (int64, error) {
 	_, msg, err := c.cmd(StatusFile, "SIZE %s", path)
 	if err != nil {
 		return 0, err
 	}
 
-	size, err := strconv.Atoi(msg)
+	size, err := strconv.ParseInt(msg, 10, 64)
 	if err != nil {
 		return 0, err
 	}