From b301b791c7cda5cffccdf9aa28bf1db6c2f9208e Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Sun, 27 Aug 2023 23:05:13 +0800 Subject: [PATCH] fix(local): set create and modified time for new file (close #4938) --- drivers/local/driver.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/local/driver.go b/drivers/local/driver.go index bf63168c..6dc05f59 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -5,6 +5,14 @@ import ( "context" "errors" "fmt" + "io/fs" + "net/http" + "os" + stdpath "path" + "path/filepath" + "strconv" + "strings" + "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/errs" @@ -13,14 +21,8 @@ import ( "github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/server/common" "github.com/djherbis/times" + log "github.com/sirupsen/logrus" _ "golang.org/x/image/webp" - "io/fs" - "net/http" - "os" - stdpath "path" - "path/filepath" - "strconv" - "strings" ) type Local struct { @@ -273,6 +275,10 @@ func (d *Local) Put(ctx context.Context, dstDir model.Obj, stream model.FileStre if err != nil { return err } + err = os.Chtimes(fullPath, stream.ModTime(), stream.ModTime()) + if err != nil { + log.Errorf("[local] failed to change time of %s: %s", fullPath, err) + } return nil }