mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
webdav: add support for parsing more time formats
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -443,7 +443,7 @@ func (f *webDavFile) Patch(patches []webdav.Proppatch) ([]webdav.Propstat, error
|
|||||||
for _, p := range patch.Props {
|
for _, p := range patch.Props {
|
||||||
if status == http.StatusForbidden && !hasError {
|
if status == http.StatusForbidden && !hasError {
|
||||||
if !patch.Remove && util.Contains(lastModifiedProps, p.XMLName.Local) {
|
if !patch.Remove && util.Contains(lastModifiedProps, p.XMLName.Local) {
|
||||||
parsed, err := http.ParseTime(string(p.InnerXML))
|
parsed, err := parseTime(string(p.InnerXML))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.Connection.Log(logger.LevelWarn, "unsupported last modification time: %q, err: %v",
|
f.Connection.Log(logger.LevelWarn, "unsupported last modification time: %q, err: %v",
|
||||||
string(p.InnerXML), err)
|
string(p.InnerXML), err)
|
||||||
|
|||||||
@@ -1611,6 +1611,15 @@ func TestMisc(t *testing.T) {
|
|||||||
certMgr = oldCertMgr
|
certMgr = oldCertMgr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseTime(t *testing.T) {
|
||||||
|
res, err := parseTime("Sat, 4 Feb 2023 17:00:50 GMT")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(1675530050), res.Unix())
|
||||||
|
res, err = parseTime("Wed, 04 Nov 2020 13:25:51 GMT")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(1604496351), res.Unix())
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigsFromProvider(t *testing.T) {
|
func TestConfigsFromProvider(t *testing.T) {
|
||||||
configDir := "."
|
configDir := "."
|
||||||
err := dataprovider.UpdateConfigs(nil, "", "", "")
|
err := dataprovider.UpdateConfigs(nil, "", "", "")
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ package webdavd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
|
|
||||||
@@ -43,6 +45,12 @@ const (
|
|||||||
var (
|
var (
|
||||||
certMgr *common.CertManager
|
certMgr *common.CertManager
|
||||||
serviceStatus ServiceStatus
|
serviceStatus ServiceStatus
|
||||||
|
timeFormats = []string{
|
||||||
|
http.TimeFormat,
|
||||||
|
"Mon, _2 Jan 2006 15:04:05 GMT",
|
||||||
|
time.RFC850,
|
||||||
|
time.ANSIC,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServiceStatus defines the service status
|
// ServiceStatus defines the service status
|
||||||
@@ -352,3 +360,13 @@ func getConfigPath(name, configDir string) string {
|
|||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseTime(text string) (t time.Time, err error) {
|
||||||
|
for _, layout := range timeFormats {
|
||||||
|
t, err = time.Parse(layout, text)
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user