1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 int
 saf_update_database(SAF_Db *database/*The database to update*/)
 {
     SAF_ENTER(saf_update_database, SAF_PRECONDITION_ERROR);
     ss_scope_t          topscope=SS_SCOPE_NULL;

     SAF_REQUIRE(SS_MAGIC(ss_file_t)==SS_MAGIC_OF(database), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("DATABASE must be a database handle"));
     SAF_REQUIRE(!_saf_database_is_read_only(database), SAF_NO_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("DATABASE must not be open for read-only access"));

     /* Synchronize all scopes of the file, then flush all scopes of the file */
     if (ss_file_synchronize(database, NULL)<0)
         SAF_ERROR(-1, _saf_errmsg("ss_file_synchronize() failed"));
     if (ss_file_flush(database, NULL)<0)
         SAF_ERROR(-1, _saf_errmsg("ss_file_flush() failed"));

     /* Flush raw data to the file */
     if (NULL==ss_pers_topscope((ss_pers_t*)database, &topscope))
         SAF_ERROR(-1, _saf_errmsg("ss_pers_topscope() failed"));
     if (ss_blob_flush(&topscope, NULL, SS_STRICT, NULL)<0)
         SAF_ERROR(-1, _saf_errmsg("ss_blob_flush() failed"));

     SAF_LEAVE(SAF_SUCCESS);
 }