Skip to content
Open
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
32 changes: 32 additions & 0 deletions file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,47 @@ func (f *ftpFile) Sys() interface{} {
}

var lsRegex = regexp.MustCompile(`^\s*(\S)(\S{3})(\S{3})(\S{3})(?:\s+\S+){3}\s+(\d+)\s+(\w+\s+\d+)\s+([\d:]+)\s+(.+)$`)
var lsRegexMS = regexp.MustCompile(`^(\d+-\d+-\d+)\s+(\d+:\d+[^ ]+)\s+([^ ]+)\s+(.*)$`)

// total 404456
// drwxr-xr-x 8 goftp 20 272 Jul 28 05:03 git-ignored
// or
// 07-23-21 05:03PM <DIR> git-dir-ignored
// 07-23-21 05:03PM 272 git-ignored
func parseLIST(entry string, loc *time.Location, skipSelfParent bool) (os.FileInfo, error) {
if strings.HasPrefix(entry, "total ") {
return nil, nil
}

matches := lsRegex.FindStringSubmatch(entry)

// on failure - try with MS format.
if len(matches) == 0 {
msmatches := lsRegexMS.FindStringSubmatch(entry)
if len(msmatches) > 0 {
// normalize MS to Unix based
matches = make([]string, 10)
matches[0] = entry
if strings.ToUpper(msmatches[3]) == "<DIR>" {
matches[1] = "d"
matches[5] = "0"
} else {
matches[1] = "-"
matches[5] = msmatches[3]
}
matches[2] = "rwx"
matches[3] = "rwx"
matches[4] = "rwx"
if d, e := time.Parse("01-02-06", msmatches[1]); e == nil {
matches[6] = d.Format("Jan _2")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're losing the year here. I noticed when parsing a Feb 29, 2008 date causing an error on re-parsing, but this will be an issue for any year prior to the current one.

}
if t, e := time.Parse("03:04pm", strings.ToLower(msmatches[2])); e == nil {
matches[7] = t.Format("15:04")
}
matches[8] = msmatches[4]
}
}

if len(matches) == 0 {
return nil, ftpError{err: fmt.Errorf(`failed parsing LIST entry: %s`, entry)}
}
Expand Down