Update vendored deps, including AWS SDK, openpgp, ftp, ...

This commit is contained in:
Andrey Smirnov
2018-04-05 17:46:45 +03:00
parent cef4fefc40
commit 0e6ee35942
1497 changed files with 450721 additions and 68034 deletions
+63 -21
View File
@@ -2,6 +2,7 @@ package ftp
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
@@ -9,10 +10,13 @@ import (
var errUnsupportedListLine = errors.New("Unsupported LIST line")
var listLineParsers = []func(line string) (*Entry, error){
type parseFunc func(string, time.Time, *time.Location) (*Entry, error)
var listLineParsers = []parseFunc{
parseRFC3659ListLine,
parseLsListLine,
parseDirListLine,
parseHostedFTPLine,
}
var dirTimeFormats = []string{
@@ -21,7 +25,7 @@ var dirTimeFormats = []string{
}
// parseRFC3659ListLine parses the style of directory line defined in RFC 3659.
func parseRFC3659ListLine(line string) (*Entry, error) {
func parseRFC3659ListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
iSemicolon := strings.Index(line, ";")
iWhitespace := strings.Index(line, " ")
@@ -39,13 +43,13 @@ func parseRFC3659ListLine(line string) (*Entry, error) {
return nil, errUnsupportedListLine
}
key := field[:i]
key := strings.ToLower(field[:i])
value := field[i+1:]
switch key {
case "modify":
var err error
e.Time, err = time.Parse("20060102150405", value)
e.Time, err = time.ParseInLocation("20060102150405", value, loc)
if err != nil {
return nil, err
}
@@ -65,7 +69,7 @@ func parseRFC3659ListLine(line string) (*Entry, error) {
// parseLsListLine parses a directory line in a format based on the output of
// the UNIX ls command.
func parseLsListLine(line string) (*Entry, error) {
func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
// Has the first field a length of 10 bytes?
if strings.IndexByte(line, ' ') != 10 {
@@ -84,7 +88,7 @@ func parseLsListLine(line string) (*Entry, error) {
Type: EntryTypeFolder,
Name: scanner.Remaining(),
}
if err := e.setTime(fields[3:6]); err != nil {
if err := e.setTime(fields[3:6], now, loc); err != nil {
return nil, err
}
@@ -99,9 +103,9 @@ 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 {
if err := e.setTime(fields[4:7], now, loc); err != nil {
return nil, err
}
@@ -131,7 +135,7 @@ func parseLsListLine(line string) (*Entry, error) {
return nil, errors.New("Unknown entry type")
}
if err := e.setTime(fields[5:8]); err != nil {
if err := e.setTime(fields[5:8], now, loc); err != nil {
return nil, err
}
@@ -140,14 +144,14 @@ func parseLsListLine(line string) (*Entry, error) {
// parseDirListLine parses a directory line in a format based on the output of
// the MS-DOS DIR command.
func parseDirListLine(line string) (*Entry, error) {
func parseDirListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
e := &Entry{}
var err error
// Try various time formats that DIR might use, and stop when one works.
for _, format := range dirTimeFormats {
if len(line) > len(format) {
e.Time, err = time.Parse(format, line[:len(format)])
e.Time, err = time.ParseInLocation(format, line[:len(format)], loc)
if err == nil {
line = line[len(format):]
break
@@ -180,11 +184,32 @@ 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, now time.Time, loc *time.Location) (*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(), now, loc)
}
// parseListLine parses the various non-standard format returned by the LIST
// FTP command.
func parseListLine(line string) (*Entry, error) {
func parseListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
for _, f := range listLineParsers {
e, err := f(line)
e, err := f(line, now, loc)
if err != errUnsupportedListLine {
return e, err
}
@@ -197,17 +222,34 @@ func (e *Entry) setSize(str string) (err error) {
return
}
func (e *Entry) setTime(fields []string) (err error) {
var timeStr string
if strings.Contains(fields[2], ":") { // this year
thisYear, _, _ := time.Now().Date()
timeStr = fields[1] + " " + fields[0] + " " + strconv.Itoa(thisYear)[2:4] + " " + fields[2] + " GMT"
} else { // not this year
func (e *Entry) setTime(fields []string, now time.Time, loc *time.Location) (err error) {
if strings.Contains(fields[2], ":") { // contains time
thisYear, _, _ := now.Date()
timeStr := fmt.Sprintf("%s %s %d %s", fields[1], fields[0], thisYear, fields[2])
e.Time, err = time.ParseInLocation("_2 Jan 2006 15:04", timeStr, loc)
/*
On unix, `info ls` shows:
10.1.6 Formatting file timestamps
---------------------------------
A timestamp is considered to be “recent” if it is less than six
months old, and is not dated in the future. If a timestamp dated today
is not listed in recent form, the timestamp is in the future, which
means you probably have clock skew problems which may break programs
like make that rely on file timestamps.
*/
if !e.Time.Before(now.AddDate(0, 6, 0)) {
e.Time = e.Time.AddDate(-1, 0, 0)
}
} else { // only the date
if len(fields[2]) != 4 {
return errors.New("Invalid year format in time string")
}
timeStr = fields[1] + " " + fields[0] + " " + fields[2][2:4] + " 00:00 GMT"
timeStr := fmt.Sprintf("%s %s %s 00:00", fields[1], fields[0], fields[2])
e.Time, err = time.ParseInLocation("_2 Jan 2006 15:04", timeStr, loc)
}
e.Time, err = time.Parse("_2 Jan 06 15:04 MST", timeStr)
return
}