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); }
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); }
/* * 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 enum pkg_infodb_format pkg_infodb_read_format(void) { struct atomic_file *file; struct stat st; char *filename; filename = dpkg_db_get_path(INFODIR "/format"); file = atomic_file_new(filename, 0); db_format = pkg_infodb_parse_format(file->name); /* Check if a previous upgrade got interrupted. Because we are only * supposed to upgrade the db layout one format at a time, if the * new file exists that means the new format is just one ahead, * we don't try to read it because it contains unreliable data. */ if (stat(file->name_new, &st) == 0) { db_format++; db_upgrading = true; } atomic_file_free(file); free(filename); if (db_format < 0 || db_format >= PKG_INFODB_FORMAT_LAST) ohshit(_("info database format (%d) is bogus or too new; " "try getting a newer dpkg"), db_format); return db_format; }
//! //! Function description. //! //! @param[in] file //! @param[in] source //! @param[in] dest //! //! @return //! //! @see //! //! @pre List of pre-conditions //! //! @post List of post conditions //! //! @note //! int atomic_file_init(atomic_file * file, char *source, char *dest, int tosort) { if (!file) { return (1); } atomic_file_free(file); snprintf(file->dest, MAX_PATH, "%s", dest); snprintf(file->source, MAX_PATH, "%s", source); snprintf(file->tmpfilebase, MAX_PATH, "%s-XXXXXX", dest); snprintf(file->tmpfile, MAX_PATH, "%s-XXXXXX", dest); file->lasthash = strdup("UNSET"); file->currhash = strdup("UNSET"); file->tosort = tosort; return (0); }
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); }