vendor: update all dependencies
This commit is contained in:
+188
@@ -268,3 +268,191 @@ func TestWrongLogin(t *testing.T) {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteDirRecur(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
c, err := DialTimeout("localhost:21", 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.Login("anonymous", "anonymous")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.NoOp()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.ChangeDir("incoming")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.MakeDir("testDir")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.ChangeDir("testDir")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.MakeDir("anotherDir")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
data := bytes.NewBufferString("test text")
|
||||
err = c.Stor("fileTest", data)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.ChangeDirToParent()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = c.RemoveDirRecur("testDir")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dir, err := c.CurrentDir()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if dir != "/incoming" {
|
||||
t.Error("Wrong dir: " + dir)
|
||||
}
|
||||
}
|
||||
|
||||
err = c.ChangeDir("testDir")
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
|
||||
err = c.Logout()
|
||||
if err != nil {
|
||||
if protoErr := err.(*textproto.Error); protoErr != nil {
|
||||
if protoErr.Code != StatusNotImplemented {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
c.Quit()
|
||||
}
|
||||
|
||||
func TestFileDeleteDirRecur(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
c, err := DialTimeout("localhost:21", 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.Login("anonymous", "anonymous")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.ChangeDir("incoming")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
data := bytes.NewBufferString(testData)
|
||||
err = c.Stor("testFile", data)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.RemoveDirRecur("testFile")
|
||||
if err == nil {
|
||||
t.Fatal("expected error got nill")
|
||||
}
|
||||
|
||||
dir, err := c.CurrentDir()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if dir != "/incoming" {
|
||||
t.Error("Wrong dir: " + dir)
|
||||
}
|
||||
}
|
||||
|
||||
err = c.Delete("testFile")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.Logout()
|
||||
if err != nil {
|
||||
if protoErr := err.(*textproto.Error); protoErr != nil {
|
||||
if protoErr.Code != StatusNotImplemented {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
c.Quit()
|
||||
}
|
||||
|
||||
func TestMissingFolderDeleteDirRecur(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
c, err := DialTimeout("localhost:21", 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.Login("anonymous", "anonymous")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = c.ChangeDir("incoming")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.RemoveDirRecur("test")
|
||||
if err == nil {
|
||||
t.Fatal("expected error got nill")
|
||||
}
|
||||
|
||||
dir, err := c.CurrentDir()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if dir != "/incoming" {
|
||||
t.Error("Wrong dir: " + dir)
|
||||
}
|
||||
}
|
||||
|
||||
err = c.Logout()
|
||||
if err != nil {
|
||||
if protoErr := err.(*textproto.Error); protoErr != nil {
|
||||
if protoErr.Code != StatusNotImplemented {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
c.Quit()
|
||||
}
|
||||
|
||||
+35
@@ -496,6 +496,41 @@ func (c *ServerConn) Delete(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveDirRecur deletes a non-empty folder recursively using
|
||||
// RemoveDir and Delete
|
||||
func (c *ServerConn) RemoveDirRecur(path string) error {
|
||||
err := c.ChangeDir(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentDir, err := c.CurrentDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entries, err := c.List(currentDir)
|
||||
for _, entry := range entries {
|
||||
if entry.Name != ".." && entry.Name != "." {
|
||||
if entry.Type == EntryTypeFolder {
|
||||
err = c.RemoveDirRecur(currentDir + "/" + entry.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = c.Delete(entry.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
err = c.ChangeDirToParent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.RemoveDir(currentDir)
|
||||
return err
|
||||
}
|
||||
|
||||
// MakeDir issues a MKD FTP command to create the specified directory on the
|
||||
// remote FTP server.
|
||||
func (c *ServerConn) MakeDir(path string) error {
|
||||
|
||||
+23
-1
@@ -13,6 +13,7 @@ var listLineParsers = []func(line string) (*Entry, error){
|
||||
parseRFC3659ListLine,
|
||||
parseLsListLine,
|
||||
parseDirListLine,
|
||||
parseHostedFTPLine,
|
||||
}
|
||||
|
||||
var dirTimeFormats = []string{
|
||||
@@ -99,7 +100,7 @@ func parseLsListLine(line string) (*Entry, error) {
|
||||
}
|
||||
|
||||
if err := e.setSize(fields[2]); err != nil {
|
||||
return nil, err
|
||||
return nil, errUnsupportedListLine
|
||||
}
|
||||
if err := e.setTime(fields[4:7]); err != nil {
|
||||
return nil, err
|
||||
@@ -180,6 +181,27 @@ func parseDirListLine(line string) (*Entry, error) {
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// parseHostedFTPLine parses a directory line in the non-standard format used
|
||||
// by hostedftp.com
|
||||
// -r-------- 0 user group 65222236 Feb 24 00:39 UABlacklistingWeek8.csv
|
||||
// (The link count is inexplicably 0)
|
||||
func parseHostedFTPLine(line string) (*Entry, error) {
|
||||
// Has the first field a length of 10 bytes?
|
||||
if strings.IndexByte(line, ' ') != 10 {
|
||||
return nil, errUnsupportedListLine
|
||||
}
|
||||
|
||||
scanner := newScanner(line)
|
||||
fields := scanner.NextFields(2)
|
||||
|
||||
if len(fields) < 2 || fields[1] != "0" {
|
||||
return nil, errUnsupportedListLine
|
||||
}
|
||||
|
||||
// Set link count to 1 and attempt to parse as Unix.
|
||||
return parseLsListLine(fields[0] + " 1 " + scanner.Remaining())
|
||||
}
|
||||
|
||||
// parseListLine parses the various non-standard format returned by the LIST
|
||||
// FTP command.
|
||||
func parseListLine(line string) (*Entry, error) {
|
||||
|
||||
+4
@@ -56,6 +56,9 @@ var listTests = []line{
|
||||
{"drwxr-xr-x 3 110 1002 3 Dec 02 2009 spaces dir name", "spaces dir name", 0, EntryTypeFolder, time.Date(2009, time.December, 2, 0, 0, 0, 0, time.UTC)},
|
||||
{"-rwxr-xr-x 3 110 1002 1234567 Dec 02 2009 file name", "file name", 1234567, EntryTypeFile, time.Date(2009, time.December, 2, 0, 0, 0, 0, time.UTC)},
|
||||
{"-rwxr-xr-x 3 110 1002 1234567 Dec 02 2009 foo bar ", " foo bar ", 1234567, EntryTypeFile, time.Date(2009, time.December, 2, 0, 0, 0, 0, time.UTC)},
|
||||
|
||||
// Odd link count from hostedftp.com
|
||||
{"-r-------- 0 user group 65222236 Feb 24 00:39 RegularFile", "RegularFile", 65222236, EntryTypeFile, time.Date(thisYear, time.February, 24, 0, 39, 0, 0, time.UTC)},
|
||||
}
|
||||
|
||||
// Not supported, we expect a specific error message
|
||||
@@ -66,6 +69,7 @@ var listTestsFail = []unsupportedLine{
|
||||
{"modify=20150806235817;invalid;UNIX.owner=0; movies", "Unsupported LIST line"},
|
||||
{"Zrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin", "Unknown entry type"},
|
||||
{"total 1", "Unsupported LIST line"},
|
||||
{"000000000x ", "Unsupported LIST line"}, // see https://github.com/jlaffaye/ftp/issues/97
|
||||
{"", "Unsupported LIST line"},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user