void DeleteMountInfo(Seq *list) { for (size_t i = 0; i < SeqLength(list); i++) { Mount *entry = SeqAt(list, i); if (entry->host) { free(entry->host); } if (entry->source) { free(entry->source); } if (entry->mounton) { free(entry->mounton); } if (entry->options) { free(entry->options); } } SeqClear(list); }
static void test_migration(void) { CF_DB *db; Seq *list = SeqNew(NO_FILES, free); // Hand crafted from the new version of NewIndexKey(). char checksum_key[NO_FILES][30] = { { 'H','_','M','D','5','\0','\0','\0','\0','\0', '/','e','t','c','/','h','o','s','t','s','\0' }, { 'H','_','M','D','5','\0','\0','\0','\0','\0', '/','e','t','c','/','p','a','s','s','w','d','\0' }, { 'H','_','M','D','5','\0','\0','\0','\0','\0', '/','f','i','l','e','1','\0' }, { 'H','_','M','D','5','\0','\0','\0','\0','\0', '/','f','i','l','e','2','\0' }, }; char *filestat_key[NO_FILES] = { "S_/etc/hosts", "S_/etc/passwd", "S_/file1", "S_/file2", }; // Should cause migration to happen. assert_true(FileChangesGetDirectoryList("/etc", list)); assert_int_equal(SeqLength(list), 2); assert_string_equal(SeqAt(list, 0), "hosts"); assert_string_equal(SeqAt(list, 1), "passwd"); SeqClear(list); assert_true(FileChangesGetDirectoryList("/", list)); assert_int_equal(SeqLength(list), 2); assert_string_equal(SeqAt(list, 0), "file1"); assert_string_equal(SeqAt(list, 1), "file2"); assert_true(OpenDB(&db, dbid_changes)); for (int c = 0; c < NO_FILES; c++) { { int ksize = 2 + CHANGES_HASH_FILE_NAME_OFFSET + strlen(checksum_key[c] + 2 + CHANGES_HASH_FILE_NAME_OFFSET) + 1; int vsize = ValueSizeDB(db, checksum_key[c], ksize); assert_int_equal(vsize, strlen(CHECKSUM_VALUE[c]) + 1); char value[vsize]; assert_true(ReadComplexKeyDB(db, checksum_key[c], ksize, value, vsize)); assert_int_equal(memcmp(value, CHECKSUM_VALUE[c], vsize), 0); } { int vsize = ValueSizeDB(db, filestat_key[c], strlen(filestat_key[c]) + 1); assert_int_equal(vsize, sizeof(struct stat)); char value[vsize]; assert_true(ReadDB(db, filestat_key[c], value, vsize)); assert_int_equal(memcmp(value, &filestat_value, vsize), 0); } } int db_entries = 0; CF_DBC *db_cursor; assert_true(NewDBCursor(db, &db_cursor)); char *key, *value; int ksize, vsize; while (NextDB(db_cursor, &key, &ksize, (void **)&value, &vsize)) { db_entries++; } DeleteDBCursor(db_cursor); // 2 x Directories ("/" and "/etc") // 4 x File hashes // 4 x File stats assert_int_equal(db_entries, 10); CloseDB(db); }