From 683ea3726634fc9bc8c8c468f1a3a43dc035e0ac Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 22 May 2024 03:34:06 +0000 Subject: [PATCH] update mtime git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@68 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Client/main.c | 2 +- Library/database.c | 8 ++++++++ Library/database_table.c | 1 + Library/dw_database.h | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Client/main.c b/Client/main.c index 062d108..44f1dda 100644 --- a/Client/main.c +++ b/Client/main.c @@ -123,7 +123,7 @@ int main(int argc, char** argv) { struct tm* tm = localtime(&mtime); char mtimestr[256]; strftime(mtimestr, 255, "%a %b %d %H:%M:%S %Z %Y", tm); - printf("Opened the database (Version %d, Modified at %s).\n", dataworks_database_get_version(db), mtimestr); + printf("Opened the database (Version %d, Modified at %s).\n", dataworks_database_get_version(db), mtimestr); printf("\n"); printf("Type a command (.help) for the help.\n"); printf("\n"); diff --git a/Library/database.c b/Library/database.c index f0e07da..85baa56 100644 --- a/Library/database.c +++ b/Library/database.c @@ -122,3 +122,11 @@ uint64_t dataworks_database_get_mtime(struct dataworks_db* db) { return db->mtim const char* dw_errors[] = {"Success", "Used already"}; const char* dataworks_database_strerror(int n) { return dw_errors[n]; } + +void dataworks_database_update_mtime(struct dataworks_db* db) { + __dw_lockfile(db->fp); + fseek(db->fp, 3 + 2, SEEK_SET); + int64_t t = time(NULL); + __dw_big_endian(t, int64_t, fwrite(__converted_ptr, 1, 8, db->fp)); + __dw_unlockfile(db->fp); +} diff --git a/Library/database_table.c b/Library/database_table.c index bc2cd58..eadc3a5 100644 --- a/Library/database_table.c +++ b/Library/database_table.c @@ -78,6 +78,7 @@ int dataworks_database_create_table(struct dataworks_db* db, const char* name, c } free(buf); __dw_unlockfile(db->fp); + dataworks_database_update_mtime(db); } } diff --git a/Library/dw_database.h b/Library/dw_database.h index b8ee6a6..b9082b5 100644 --- a/Library/dw_database.h +++ b/Library/dw_database.h @@ -212,6 +212,14 @@ int dataworks_database_create_table(struct dataworks_db* db, const char* name, c */ const char* dataworks_database_strerror(int n); +/** + * @~english + * @brief Update mtime. + * @param db Database + * + */ +void dataworks_database_update_mtime(struct dataworks_db* db); + #ifdef __cplusplus } #endif -- 2.43.0