Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : * @brief Verify that the primary database file changed only when expected
5 : : *
6 : : * Compares the saved primary-database metadata captured earlier in the run with
7 : : * the current metadata on disk. A real metadata change is expected only when
8 : : * `config->db_primary_file_modified` is true. If the file changed without that
9 : : * flag, or the flag is set but metadata did not change, the function reports an
10 : : * internal consistency warning
11 : : *
12 : : * @return SUCCESS when the metadata and modification flag agree, WARNING when
13 : : * they disagree, or FAILURE when current database metadata cannot be read
14 : : */
15 : 116 : Return db_check_changes(void)
16 : : {
17 : : /* Status returned by this function through provide()
18 : : Default value assumes successful completion */
19 : 116 : Return status = SUCCESS;
20 : :
21 : 116 : struct stat db_current_stat = {0};
22 : :
23 : : #ifdef TESTITALL_TEST_HOOKS
24 [ + - ]: 116 : if(SUCCESS == status)
25 : : {
26 : 116 : status = testitall_db_bump_timestamps();
27 : : }
28 : : #endif
29 : :
30 : 116 : int rc = stat(confstr(db_primary_file_path),&db_current_stat);
31 : :
32 [ - + ]: 116 : if(rc < 0)
33 : : {
34 : 0 : report("Stat of %s failed with error code: %d",confstr(db_primary_file_path),rc);
35 : 0 : status = FAILURE;
36 : : }
37 : :
38 : : #ifdef TESTITALL_TEST_HOOKS
39 [ + - ]: 116 : if(SUCCESS == status)
40 : : {
41 : 116 : status = testitall_db_resync_stat_baseline(&db_current_stat);
42 : : }
43 : : #endif
44 : :
45 : 116 : CmpctStat before = {0};
46 : 116 : CmpctStat after = {0};
47 : :
48 : 116 : run(stat_copy(&config->db_file_stat,&before));
49 : 116 : run(stat_copy(&db_current_stat,&after));
50 : :
51 : 116 : Changed changes = file_compare_metadata_equivalence(&before,&after);
52 : :
53 [ + + ]: 116 : if(IDENTICAL != changes)
54 : : {
55 [ + + ]: 70 : if(config->db_primary_file_modified == true)
56 : : {
57 : 68 : slog(EVERY,BOLD "The database file %s has been modified since the program was launched" RESET "\n",confstr(db_file_name));
58 : : } else {
59 : 2 : slog(ERROR,"Internal error: The database file %s has changed, but according to the global variable tracking modification status, this should not have happened!\n",confstr(db_file_name));
60 : :
61 [ + - ]: 2 : if(!(rational_logger_mode & SILENT))
62 : : {
63 : 2 : show_difference(changes,&before,&after);
64 : : }
65 : 2 : status = WARNING;
66 : : }
67 : : } else {
68 [ + + ]: 46 : if(config->db_primary_file_modified == true)
69 : : {
70 : 2 : slog(ERROR,"Internal error. The database file %s has NOT changed, but according to the state of the global variable tracking modifications, it should have!\n",confstr(db_file_name));
71 : 2 : status = WARNING;
72 : : } else {
73 : 44 : slog(EVERY,BOLD "The database file %s has NOT been modified since the program was launched" RESET "\n",confstr(db_file_name));
74 : : }
75 : : }
76 : :
77 : 116 : provide(status);
78 : : }
|