From 36e04f33f5e421b7520ab0f5e8ad719036247ff0 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 5 Apr 2017 10:44:28 +0800 Subject: [PATCH] esp32: ROMFS use checksum as mtime so ETAG caching works --- lib/lws-plat-esp32.c | 6 ++++-- lib/romfs.c | 4 +++- lib/romfs.h | 2 +- plugins/protocol_esp32_lws_scan.c | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/lws-plat-esp32.c b/lib/lws-plat-esp32.c index 82e39ce4..e14d96d2 100644 --- a/lib/lws-plat-esp32.c +++ b/lib/lws-plat-esp32.c @@ -653,13 +653,13 @@ esp32_lws_fops_open(const struct lws_plat_file_ops *fops, const char *filename, { struct esp32_file *f = malloc(sizeof(*f)); lws_fop_fd_t fop_fd; - size_t len; + size_t len, csum; lwsl_notice("%s: %s\n", __func__, filename); if (!f) return NULL; - f->i = romfs_get_info(lws_esp32_romfs, filename, &len); + f->i = romfs_get_info(lws_esp32_romfs, filename, &len, &csum); if (!f->i) goto bail; @@ -669,6 +669,8 @@ esp32_lws_fops_open(const struct lws_plat_file_ops *fops, const char *filename, fop_fd->fops = fops; fop_fd->filesystem_priv = f; + fop_fd->mod_time = csum; + *flags |= LWS_FOP_FLAG_MOD_TIME_VALID; fop_fd->flags = *flags; fop_fd->len = len; diff --git a/lib/romfs.c b/lib/romfs.c index 1f6d2f2e..540382e6 100644 --- a/lib/romfs.c +++ b/lib/romfs.c @@ -203,7 +203,7 @@ romfs_lookup(romfs_t romfs, romfs_inode_t start, const char *path) } const void * -romfs_get_info(romfs_t romfs, const char *path, size_t *len) +romfs_get_info(romfs_t romfs, const char *path, size_t *len, size_t *csum) { romfs_inode_t i; @@ -217,6 +217,8 @@ romfs_get_info(romfs_t romfs, const char *path, size_t *len) set_cache(i, sizeof(*i)); *len = ntohl(ci->size); + if (csum) + *csum = ntohl(ci->checksum); return (void *)skip_and_pad(i); } diff --git a/lib/romfs.h b/lib/romfs.h index 0de35731..dab932b9 100644 --- a/lib/romfs.h +++ b/lib/romfs.h @@ -57,7 +57,7 @@ typedef const struct romfs_i *romfs_inode_t; typedef const struct romfs_superblock *romfs_t; const void * -romfs_get_info(romfs_t romfs, const char *path, size_t *len); +romfs_get_info(romfs_t romfs, const char *path, size_t *len, size_t *csum); size_t romfs_mount_check(romfs_t romfs); diff --git a/plugins/protocol_esp32_lws_scan.c b/plugins/protocol_esp32_lws_scan.c index 51c808c6..ebb36db3 100644 --- a/plugins/protocol_esp32_lws_scan.c +++ b/plugins/protocol_esp32_lws_scan.c @@ -173,7 +173,7 @@ static void reboot_timer_cb(TimerHandle_t t) static int client_connection(struct per_vhost_data__esplws_scan *vhd, const char *file) { -#if CONFIG_LWS_IS_FACTORY_APPLICATION == 'y' && defined(CONFIG_LWS_OTA_SERVER_BASE_URL) && +#if CONFIG_LWS_IS_FACTORY_APPLICATION == 'y' && defined(CONFIG_LWS_OTA_SERVER_BASE_URL) && \ defined(CONFIG_LWS_OTA_SERVER_FQDN) static struct lws_client_connect_info i; char path[256];