Parcourir la source

Quick fix for files in memory (#382) (Step 2/?)

bel il y a 8 ans
Parent
commit
3c8717fb76
2 fichiers modifiés avec 10 ajouts et 4 suppressions
  1. 4 1
      src/civetweb.c
  2. 6 3
      test/public_server.c

+ 4 - 1
src/civetweb.c

@@ -3666,7 +3666,10 @@ mg_stat(const struct mg_connection *conn,
 
 		/* Quick fix (for 1.9.x): */
 		/* mg_stat must fill all fields, also for files in memory */
-		open_file_in_memory(conn, path, filep, MG_FOPEN_MODE_NONE);
+        struct mg_file tmp_file;
+		open_file_in_memory(conn, path, &tmp_file, MG_FOPEN_MODE_NONE);
+        filep->size = tmp_file.stat.size;
+        filep->location = 2;
 		/* TODO: for 1.10: restructure how files in memory are handled */
 
 		filep->last_modified = time(NULL); /* xxxxxxxx */

+ 6 - 3
test/public_server.c

@@ -3691,6 +3691,9 @@ START_TEST(test_large_file)
 }
 END_TEST
 
+
+#if !defined(NO_FILES)
+
 #define FILE_IN_MEM_SIZE (1024 * 100)
 static char *file_in_mem_data;
 
@@ -3710,6 +3713,7 @@ test_file_in_memory_open_file(const struct mg_connection *conn,
 		return NULL;
 	}
 }
+#endif
 
 
 START_TEST(test_file_in_memory)
@@ -3816,9 +3820,8 @@ START_TEST(test_file_in_memory)
 	free(file_in_mem_data);
 	file_in_mem_data = NULL;
 #else
-	/* This test is not meaningful, if NO_FILES is set */
-	/* Use file_in_mem_data (to avoid unused warning) */
-	ck_assert_ptr_eq(file_in_mem_data, NULL);
+	/* This test is not meaningful, if NO_FILES is set */	
+	ck_assert_uint_eq(mg_check_feature(1), 0);
 #endif
 }
 END_TEST