Skip to content

Commit

Permalink
rawx: return Last-Modified in HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fvennetier committed Mar 26, 2021
1 parent 34f08c0 commit 1a7f97c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rawx/chunk_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strconv"
"strings"
"syscall"
"time"
)

type chunkInfo struct {
Expand All @@ -46,6 +47,7 @@ type chunkInfo struct {
OioVersion string `json:"oio_version,omitempty"`

compression string
mtime time.Time
size int64
}

Expand Down Expand Up @@ -231,6 +233,7 @@ func loadAttr(inChunk fileReader, chunkID string, reqid string) (chunkInfo, erro
}
}

chunk.mtime = inChunk.mtime()
chunk.size, err = strconv.ParseInt(chunk.ChunkSize, 10, 63)
if err != nil {
err = errMissingXattr(AttrNameChunkSize, err)
Expand Down Expand Up @@ -487,6 +490,7 @@ func (chunk chunkInfo) fillHeaders(headers http.Header) {
setHeader(headers, HeaderNameChunkChecksum, chunk.ChunkHash)
setHeader(headers, HeaderNameChunkSize, chunk.ChunkSize)
setHeader(headers, HeaderNameXattrVersion, chunk.OioVersion)
setHeader(headers, "Last-Modified", chunk.mtime.Format(time.RFC1123))
}

// Fill the headers of the reply with the chunk info calculated by the rawx
Expand Down
10 changes: 10 additions & 0 deletions rawx/filerepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

syscall "golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -393,6 +394,15 @@ func (fr *realFileReader) fd() int {
return int(fr.f.Fd())
}

func (fr *realFileReader) mtime() time.Time {
fi, err := fr.f.Stat()
if err != nil {
return time.Unix(0, 0)
} else {
return fi.ModTime()
}
}

func (fr *realFileReader) size() int64 {
fi, err := fr.f.Stat()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions rawx/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"io"
"os"
"time"
)

type decorable interface {
Expand All @@ -31,6 +32,7 @@ type fileReader interface {
// Return the underlying os.File
File() *os.File

mtime() time.Time
size() int64
seek(int64) error
getAttr(key string, value []byte) (int, error)
Expand Down

0 comments on commit 1a7f97c

Please sign in to comment.