forked from mirrors/kore
let filerefs to operate on ms precision for mtime.
This commit is contained in:
parent
a6e662a805
commit
cf1f624367
|
@ -51,6 +51,7 @@ extern "C" {
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#undef daemon
|
#undef daemon
|
||||||
extern int daemon(int, int);
|
extern int daemon(int, int);
|
||||||
|
#define st_mtim st_mtimespec
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(KORE_NO_SENDFILE) && defined(KORE_NO_TLS)
|
#if !defined(KORE_NO_SENDFILE) && defined(KORE_NO_TLS)
|
||||||
|
@ -116,7 +117,8 @@ struct kore_fileref {
|
||||||
int flags;
|
int flags;
|
||||||
off_t size;
|
off_t size;
|
||||||
char *path;
|
char *path;
|
||||||
time_t mtime;
|
u_int64_t mtime;
|
||||||
|
time_t mtime_sec;
|
||||||
u_int64_t expiration;
|
u_int64_t expiration;
|
||||||
#if !defined(KORE_USE_PLATFORM_SENDFILE)
|
#if !defined(KORE_USE_PLATFORM_SENDFILE)
|
||||||
void *base;
|
void *base;
|
||||||
|
@ -675,7 +677,8 @@ extern char *kore_filemap_index;
|
||||||
|
|
||||||
void kore_fileref_init(void);
|
void kore_fileref_init(void);
|
||||||
struct kore_fileref *kore_fileref_get(const char *);
|
struct kore_fileref *kore_fileref_get(const char *);
|
||||||
struct kore_fileref *kore_fileref_create(const char *, int, off_t, time_t);
|
struct kore_fileref *kore_fileref_create(const char *, int, off_t,
|
||||||
|
struct timespec *);
|
||||||
void kore_fileref_release(struct kore_fileref *);
|
void kore_fileref_release(struct kore_fileref *);
|
||||||
|
|
||||||
void kore_domain_init(void);
|
void kore_domain_init(void);
|
||||||
|
|
|
@ -272,7 +272,7 @@ lookup:
|
||||||
|
|
||||||
/* kore_fileref_create() takes ownership of the fd. */
|
/* kore_fileref_create() takes ownership of the fd. */
|
||||||
ref = kore_fileref_create(fpath, fd,
|
ref = kore_fileref_create(fpath, fd,
|
||||||
st.st_size, st.st_mtime);
|
st.st_size, &st.st_mtim);
|
||||||
if (ref == NULL) {
|
if (ref == NULL) {
|
||||||
http_response(req,
|
http_response(req,
|
||||||
HTTP_STATUS_INTERNAL_ERROR, NULL, 0);
|
HTTP_STATUS_INTERNAL_ERROR, NULL, 0);
|
||||||
|
|
|
@ -44,7 +44,7 @@ kore_fileref_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kore_fileref *
|
struct kore_fileref *
|
||||||
kore_fileref_create(const char *path, int fd, off_t size, time_t mtime)
|
kore_fileref_create(const char *path, int fd, off_t size, struct timespec *ts)
|
||||||
{
|
{
|
||||||
struct kore_fileref *ref;
|
struct kore_fileref *ref;
|
||||||
|
|
||||||
|
@ -56,12 +56,15 @@ kore_fileref_create(const char *path, int fd, off_t size, time_t mtime)
|
||||||
ref->cnt = 1;
|
ref->cnt = 1;
|
||||||
ref->flags = 0;
|
ref->flags = 0;
|
||||||
ref->size = size;
|
ref->size = size;
|
||||||
ref->mtime = mtime;
|
|
||||||
ref->path = kore_strdup(path);
|
ref->path = kore_strdup(path);
|
||||||
|
ref->mtime_sec = ts->tv_sec;
|
||||||
|
ref->mtime = ((u_int64_t)(ts->tv_sec * 1000 + (ts->tv_nsec / 1000000)));
|
||||||
|
|
||||||
#if !defined(KORE_USE_PLATFORM_SENDFILE)
|
#if !defined(KORE_USE_PLATFORM_SENDFILE)
|
||||||
if ((uintmax_t)size> SIZE_MAX)
|
if ((uintmax_t)size> SIZE_MAX) {
|
||||||
|
kore_pool_put(&ref_pool, ref);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
ref->base = mmap(NULL, (size_t)size, PROT_READ, MAP_PRIVATE, fd, 0);
|
ref->base = mmap(NULL, (size_t)size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (ref->base == MAP_FAILED)
|
if (ref->base == MAP_FAILED)
|
||||||
|
@ -91,6 +94,7 @@ kore_fileref_get(const char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct kore_fileref *ref;
|
struct kore_fileref *ref;
|
||||||
|
u_int64_t mtime;
|
||||||
|
|
||||||
TAILQ_FOREACH(ref, &refs, list) {
|
TAILQ_FOREACH(ref, &refs, list) {
|
||||||
if (!strcmp(ref->path, path)) {
|
if (!strcmp(ref->path, path)) {
|
||||||
|
@ -101,7 +105,10 @@ kore_fileref_get(const char *path)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st.st_mtime != ref->mtime) {
|
mtime = ((u_int64_t)(st.st_mtim.tv_sec * 1000 +
|
||||||
|
(st.st_mtim.tv_nsec / 1000000)));
|
||||||
|
|
||||||
|
if (ref->mtime != mtime) {
|
||||||
fileref_soft_remove(ref);
|
fileref_soft_remove(ref);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -568,14 +568,14 @@ http_response_fileref(struct http_request *req, int status,
|
||||||
|
|
||||||
if (http_request_header(req, "if-modified-since", &modified)) {
|
if (http_request_header(req, "if-modified-since", &modified)) {
|
||||||
mtime = kore_date_to_time(modified);
|
mtime = kore_date_to_time(modified);
|
||||||
if (mtime == ref->mtime) {
|
if (mtime == ref->mtime_sec) {
|
||||||
kore_fileref_release(ref);
|
kore_fileref_release(ref);
|
||||||
http_response(req, HTTP_STATUS_NOT_MODIFIED, NULL, 0);
|
http_response(req, HTTP_STATUS_NOT_MODIFIED, NULL, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tm = gmtime(&ref->mtime)) != NULL) {
|
if ((tm = gmtime(&ref->mtime_sec)) != NULL) {
|
||||||
if (strftime(tbuf, sizeof(tbuf),
|
if (strftime(tbuf, sizeof(tbuf),
|
||||||
"%a, %d %b %Y %H:%M:%S GMT", tm) > 0) {
|
"%a, %d %b %Y %H:%M:%S GMT", tm) > 0) {
|
||||||
http_response_header(req, "last-modified", tbuf);
|
http_response_header(req, "last-modified", tbuf);
|
||||||
|
|
Loading…
Reference in New Issue