Browse Source

Merge pull request #149 from PhilLab/patch-1

Last-Modified timestamp based on creation time
bel2125 10 years ago
parent
commit
c55b27dbfd
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/civetweb.c

+ 12 - 0
src/civetweb.c

@@ -2385,6 +2385,18 @@ mg_stat(struct mg_connection *conn, const char *path, struct file *filep)
 			filep->modification_time =
 			    SYS2UNIX_TIME(info.ftLastWriteTime.dwLowDateTime,
 			                  info.ftLastWriteTime.dwHighDateTime);
+
+			/* On Windows, the file creation time can be higher than the
+			 * modification time, e.g. when a file is copied.
+			 * Since the Last-Modified timestamp is used for caching
+			 * it should be based on the most recent timestamp. */
+			time_t creation_time =
+			    SYS2UNIX_TIME(info.ftCreationTime.dwLowDateTime,
+			                  info.ftCreationTime.dwHighDateTime);
+			if (creation_time > filep->modification_time) {
+				filep->modification_time = creation_time;
+			}
+
 			filep->is_directory =
 			    info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
 			/* If file name is fishy, reset the file structure and return