]> Sergey Matveev's repositories - godlighty.git/commitdiff
Use mtime instead of ctime master
authorSergey Matveev <stargrave@stargrave.org>
Tue, 26 Mar 2024 08:42:08 +0000 (11:42 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 26 Mar 2024 08:46:36 +0000 (11:46 +0300)
To be able to get same ETags on different servers.

go.mod
go.sum
godlighty.go
handler.go
mtime.go [moved from ctime.go with 75% similarity]

diff --git a/go.mod b/go.mod
index 2278137418aae87eb1d775773f8007d4e4d8d7bd..5eefacf8af387d69f087692b59f2d3b5e608900b 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -7,5 +7,4 @@ require (
        github.com/dustin/go-humanize v1.0.1
        github.com/klauspost/compress v1.17.7
        golang.org/x/net v0.19.0
-       golang.org/x/sys v0.15.0
 )
diff --git a/go.sum b/go.sum
index 4dcbfbcfdfd5cedb3ea712212328e516c2093100..8693e67b119adac73d11887224ef1f6ce3ed3a53 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -6,5 +6,3 @@ github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLA
 github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
 golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
 golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
-golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
-golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
index 8b141c6717eec6f0bb8e4e23bfa0608b818fccdb..ee2ff75011ed574e882f67cbb26ae1f4f4d8f64f 100644 (file)
@@ -1,6 +1,6 @@
 // Highly-customizable HTTP, HTTP/2, HTTPS server
 package godlighty
 
-const Version = "godlighty/0.6.0"
+const Version = "godlighty/0.7.0"
 
 var BindAddr string
index 354b5053bebc8a7b2d0216ee8e2c7c49e2697ba1..10b0d2ff83f0b7b557be80494eea1389e8d0e31b 100644 (file)
@@ -194,7 +194,7 @@ IndexLookuped:
                                http.Error(w, "internal error", http.StatusInternalServerError)
                                return
                        }
-                       etag, err = ctimeETag(fd)
+                       etag, err = mtimeETag(fd)
                        fd.Close()
                        if err != nil {
                                printErr(http.StatusInternalServerError, err)
@@ -240,7 +240,7 @@ IndexLookuped:
                        http.Error(w, "internal error", http.StatusInternalServerError)
                        return
                }
-               etag, err = ctimeETag(fd)
+               etag, err = mtimeETag(fd)
                if err != nil {
                        printErr(http.StatusInternalServerError, err)
                        http.Error(w, "internal error", http.StatusInternalServerError)
similarity index 75%
rename from ctime.go
rename to mtime.go
index 72047e6a4cf67a5d5a8bf86c6a37e3ff086c149f..35afa482946cbaf52b049807e757087d53d19914 100644 (file)
--- a/ctime.go
+++ b/mtime.go
@@ -19,19 +19,17 @@ import (
        "encoding/base64"
        "encoding/binary"
        "os"
-
-       "golang.org/x/sys/unix"
 )
 
-func ctimeETag(fd *os.File) (string, error) {
-       var stat unix.Stat_t
-       err := unix.Fstat(int(fd.Fd()), &stat)
+func mtimeETag(fd *os.File) (string, error) {
+       fi, err := fd.Stat()
        if err != nil {
                return "", err
        }
-       sec, nsec := stat.Ctim.Unix()
-       buf := make([]byte, 8*2)
-       binary.BigEndian.PutUint64(buf[:8], uint64(sec))
-       binary.BigEndian.PutUint64(buf[8:], uint64(nsec))
+       mtime := fi.ModTime()
+       buf := make([]byte, 8*3)
+       binary.BigEndian.PutUint64(buf[:8], uint64(fi.Size()))
+       binary.BigEndian.PutUint64(buf[8:16], uint64(mtime.Unix()))
+       binary.BigEndian.PutUint64(buf[16:], uint64(mtime.Nanosecond()))
        return `"` + base64.RawURLEncoding.EncodeToString(buf) + `"`, nil
 }