From b602fb0ade9628d43ea75360e8aa59cce4ab59c8 Mon Sep 17 00:00:00 2001 From: Marcel Hauf Date: Fri, 4 Nov 2022 11:00:15 +0100 Subject: [PATCH 1/3] Support LIST responses without a group --- parse.go | 13 +++++++++++-- parse_test.go | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/parse.go b/parse.go index dbe0324..9008684 100644 --- a/parse.go +++ b/parse.go @@ -127,10 +127,19 @@ func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, er e := &Entry{ Name: scanner.Remaining(), } + sizeIndex := 4 + timeIndex := 5 + // Last field may be the name + if len(e.Name) == 0 { + e.Name = fields[7] + sizeIndex = 3 + timeIndex = 4 + } + switch fields[0][0] { case '-': e.Type = EntryTypeFile - if err := e.setSize(fields[4]); err != nil { + if err := e.setSize(fields[sizeIndex]); err != nil { return nil, err } case 'd': @@ -147,7 +156,7 @@ func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, er return nil, errUnknownListEntryType } - if err := e.setTime(fields[5:8], now, loc); err != nil { + if err := e.setTime(fields[timeIndex:timeIndex+3], now, loc); err != nil { return nil, err } diff --git a/parse_test.go b/parse_test.go index 8bcd45a..ad35f09 100644 --- a/parse_test.go +++ b/parse_test.go @@ -48,6 +48,8 @@ var listTests = []line{ {"drwxr-xr-x folder 0 Aug 15 05:49 !!!-Tipp des Haus!", "!!!-Tipp des Haus!", 0, EntryTypeFolder, newTime(thisYear, time.August, 15, 5, 49)}, {"drwxrwxrwx folder 0 Aug 11 20:32 P0RN", "P0RN", 0, EntryTypeFolder, newTime(thisYear, time.August, 11, 20, 32)}, {"-rw-r--r-- 0 18446744073709551615 18446744073709551615 Nov 16 2006 VIDEO_TS.VOB", "VIDEO_TS.VOB", 18446744073709551615, EntryTypeFile, newTime(2006, time.November, 16)}, + {"-rw-rw-rw- 1 generic 103344 Jan 03 15:12 test.pdf", "test.pdf", 103344, EntryTypeFile, newTime(thisYear, time.January, 3, 15, 12)}, + {"drw-rw-rw- 3 generic 4096 Jan 03 16:31 pub", "pub", 0, EntryTypeFolder, newTime(thisYear, time.January, 3, 16, 31)}, // Microsoft's FTP servers for Windows {"---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z", "ls-lR.Z", 1803128, EntryTypeFile, newTime(thisYear, time.July, 10, 10, 18)}, From 2473defac4b6bfb8dd00a24c5a6b7fb1668d1e67 Mon Sep 17 00:00:00 2001 From: Marcel Hauf Date: Fri, 4 Nov 2022 11:18:07 +0100 Subject: [PATCH 2/3] Hard fork the module --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 027c353..f533546 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rclone/ftp +module github.com/chi-deutschland/ftp go 1.14 From 00d862d64c396ac757e4153d042278668cea63d3 Mon Sep 17 00:00:00 2001 From: Marcel Hauf Date: Tue, 8 Nov 2022 14:19:53 +0100 Subject: [PATCH 3/3] Support LIST responses without a group and whitespaces in Name --- parse.go | 16 +++++++++++++--- parse_test.go | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/parse.go b/parse.go index 9008684..9c02280 100644 --- a/parse.go +++ b/parse.go @@ -71,6 +71,11 @@ func parseRFC3659ListLine(line string, now time.Time, loc *time.Location) (*Entr return e, nil } +func isNumber(str string) bool { + _, err := strconv.ParseUint(str, 0, 64) + return err == nil +} + // parseLsListLine parses a directory line in a format based on the output of // the UNIX ls command. func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) { @@ -129,11 +134,16 @@ func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, er } sizeIndex := 4 timeIndex := 5 - // Last field may be the name - if len(e.Name) == 0 { - e.Name = fields[7] + + // Assume group or user is missing + if !isNumber(fields[2]) && isNumber(fields[3]) { sizeIndex = 3 timeIndex = 4 + if len(e.Name) > 0 { + e.Name = fields[7] + " " + e.Name + } else { + e.Name = fields[7] + } } switch fields[0][0] { diff --git a/parse_test.go b/parse_test.go index ad35f09..99e629b 100644 --- a/parse_test.go +++ b/parse_test.go @@ -50,6 +50,7 @@ var listTests = []line{ {"-rw-r--r-- 0 18446744073709551615 18446744073709551615 Nov 16 2006 VIDEO_TS.VOB", "VIDEO_TS.VOB", 18446744073709551615, EntryTypeFile, newTime(2006, time.November, 16)}, {"-rw-rw-rw- 1 generic 103344 Jan 03 15:12 test.pdf", "test.pdf", 103344, EntryTypeFile, newTime(thisYear, time.January, 3, 15, 12)}, {"drw-rw-rw- 3 generic 4096 Jan 03 16:31 pub", "pub", 0, EntryTypeFolder, newTime(thisYear, time.January, 3, 16, 31)}, + {"-rw-rw-rw- 1 generic 29203 Jan 08 13:22 first_part second.part third.part.xml", "first_part second.part third.part.xml", 29203, EntryTypeFile, newTime(thisYear, time.January, 8, 13, 22)}, // Microsoft's FTP servers for Windows {"---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z", "ls-lR.Z", 1803128, EntryTypeFile, newTime(thisYear, time.July, 10, 10, 18)},