@@ -102,17 +102,19 @@ file_cache_ptr FileCache::Open(const char* filepath, OpenParam* param) {
102102 // Lock order: LRUCache mutex → fc->mutex (never reverse).
103103 {
104104 std::lock_guard<std::mutex> lock (fc->mutex );
105- // Sync local stat result into cached entry
106- fc->st = st;
107- if (S_ISREG (fc->st .st_mode )) {
108- param->filesize = fc->st .st_size ;
105+ if (S_ISREG (st.st_mode )) {
106+ param->filesize = st.st_size ;
109107 // FILE
110108 if (param->need_read ) {
111- if (fc-> st .st_size > param->max_read ) {
109+ if (st.st_size > param->max_read ) {
112110 param->error = ERR_OVER_LIMIT;
113- // Don't cache incomplete entries
111+ // Leave existing cache entry's state untouched
114112 return NULL ;
115113 }
114+ }
115+ // Validation passed — commit new stat into cached entry
116+ fc->st = st;
117+ if (param->need_read ) {
116118 fc->resize_buf (fc->st .st_size , max_header_length);
117119 // Loop to handle partial reads (EINTR, etc.)
118120 char * dst = fc->filebuf .base ;
@@ -145,8 +147,9 @@ file_cache_ptr FileCache::Open(const char* filepath, OpenParam* param) {
145147 fc->content_type = http_content_type_str_by_suffix (suffix + 1 );
146148 }
147149 }
148- } else if (S_ISDIR (fc-> st .st_mode )) {
150+ } else if (S_ISDIR (st.st_mode )) {
149151 // DIR
152+ fc->st = st;
150153 std::string page;
151154 make_index_of_page (filepath, page, param->path );
152155 fc->resize_buf (page.size (), max_header_length);
0 commit comments