Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LIST responses without a group #2

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/rclone/ftp
module github.com/chi-deutschland/ftp

go 1.14

Expand Down
23 changes: 21 additions & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -127,10 +132,24 @@ func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, er
e := &Entry{
Name: scanner.Remaining(),
}
sizeIndex := 4
timeIndex := 5

// 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] {
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':
Expand All @@ -147,7 +166,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
}

Expand Down
3 changes: 3 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ 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)},
{"-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)},
Expand Down