static void statdb_write(void) { char *dbname; struct atomic_file *dbfile; struct fileiterator *iter; struct filenamenode *file; dbname = dpkg_db_get_path(STATOVERRIDEFILE); dbfile = atomic_file_new(dbname, aff_backup); atomic_file_open(dbfile); iter = files_db_iter_new(); while ((file = files_db_iter_next(iter))) statdb_node_print(dbfile->fp, file); files_db_iter_free(iter); atomic_file_sync(dbfile); atomic_file_close(dbfile); atomic_file_commit(dbfile); atomic_file_free(dbfile); dir_sync_path(dpkg_db_get_dir()); free(dbname); }
static void divertdb_write(void) { char *dbname; struct atomic_file *file; struct fsys_hash_iter *iter; struct fsys_namenode *namenode; dbname = dpkg_db_get_path(DIVERSIONSFILE); file = atomic_file_new(dbname, ATOMIC_FILE_BACKUP); atomic_file_open(file); iter = fsys_hash_iter_new(); while ((namenode = fsys_hash_iter_next(iter))) { struct fsys_diversion *d = namenode->divert; if (d == NULL || d->useinstead == NULL) continue; fprintf(file->fp, "%s\n%s\n%s\n", d->useinstead->divert->camefrom->name, d->useinstead->name, diversion_pkg_name(d)); } fsys_hash_iter_free(iter); atomic_file_sync(file); atomic_file_close(file); atomic_file_commit(file); atomic_file_free(file); free(dbname); }
/* * If mask is nonzero, will not write any file whose filenamenode * has any flag bits set in mask. */ void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin, struct fileinlist *list, enum fnnflags mask) { struct atomic_file *file; const char *listfile; listfile = pkg_infodb_get_file(pkg, pkgbin, LISTFILE); file = atomic_file_new(listfile, 0); atomic_file_open(file); while (list) { if (!(mask && (list->namenode->flags & mask))) { fputs(list->namenode->name, file->fp); putc('\n', file->fp); } list= list->next; } atomic_file_sync(file); atomic_file_close(file); atomic_file_commit(file); atomic_file_free(file); dir_sync_path(pkg_infodb_get_dir()); note_must_reread_files_inpackage(pkg); }
static void trk_explicit_interest_change(const char *trig, struct pkginfo *pkg, struct pkgbin *pkgbin, int signum, enum trig_options opts) { char buf[1024]; struct atomic_file *file; bool empty = true; trk_explicit_start(trig); file = atomic_file_new(trk_explicit_fn.buf, 0); atomic_file_open(file); while (trk_explicit_f && trk_explicit_fgets(buf, sizeof(buf)) >= 0) { const char *pkgname = pkgbin_name(pkg, pkgbin, pnaw_nonambig); size_t len = strlen(pkgname); if (strncmp(buf, pkgname, len) == 0 && len < sizeof(buf) && (buf[len] == '\0' || buf[len] == '/')) continue; fprintf(file->fp, "%s\n", buf); empty = false; } if (signum > 0) { fprintf(file->fp, "%s%s\n", pkgbin_name(pkg, pkgbin, pnaw_nonambig), (opts == TRIG_NOAWAIT) ? "/noawait" : ""); empty = false; } if (!empty) atomic_file_sync(file); atomic_file_close(file); if (empty) atomic_file_remove(file); else atomic_file_commit(file); atomic_file_free(file); dir_sync_path(triggersdir); }
static void trig_file_interests_update(void) { struct trigfileint *tfi; struct atomic_file *file; file = atomic_file_new(triggersfilefile, 0); atomic_file_open(file); for (tfi = filetriggers.head; tfi; tfi = tfi->inoverall.next) fprintf(file->fp, "%s %s%s\n", trigh.namenode_name(tfi->fnn), pkgbin_name(tfi->pkg, tfi->pkgbin, pnaw_nonambig), (tfi->options == TRIG_NOAWAIT) ? "/noawait" : ""); atomic_file_sync(file); atomic_file_close(file); atomic_file_commit(file); atomic_file_free(file); }