void cu_installsharedconf(int argc, void **argv) { struct fileinlist *nifd = (struct fileinlist*)argv[0]; struct filenamenode *namenode; struct stat stab; cleanup_pkg_failed++; cleanup_conflictor_failed++; namenode = nifd->namenode; debug(dbg_eachfile, "cu_installsharedconf `%s' flags=%o", namenode->name, namenode->flags); setupfnamevbs(namenode->name); if ((namenode->flags & fnnf_new_conff) && !lstat(fnametmpvb.buf, &stab)) { /* OK, <foo>.dpkg-tmp exists. Restore it to <foo>.dpkg-new as it was a * previously unpacked (but not configured) configuration file. */ if (secure_remove(fnamenewvb.buf) && errno != ENOENT && errno != ENOTDIR) ohshite(_("unable to remove newly-installed version of `%.250s' to allow" " reinstallation of backup copy"), fnamenewvb.buf); /* Either we can do an atomic restore, or we've made room: */ if (rename(fnametmpvb.buf, fnamenewvb.buf)) ohshite(_("unable to restore backup version of `%.250s'"), fnamenewvb.buf); } else { debug(dbg_eachfiledetail,"cu_installsharedconf not restoring"); } cleanup_pkg_failed--; cleanup_conflictor_failed--; }
/** * Something went wrong and we're undoing. * * We have the following possible situations for non-conffiles: * «pathname».dpkg-tmp exists - in this case we want to remove * «pathname» if it exists and replace it with «pathname».dpkg-tmp. * This undoes the backup operation. * «pathname».dpkg-tmp does not exist - «pathname» may be on the disk, * as a new file which didn't fail, remove it if it is. * * In both cases, we also make sure we delete «pathname».dpkg-new in * case that's still hanging around. * * For conffiles, we simply delete «pathname».dpkg-new. For these, * «pathname».dpkg-tmp shouldn't exist, as we don't make a backup * at this stage. Just to be on the safe side, though, we don't * look for it. */ void cu_installnew(int argc, void **argv) { struct filenamenode *namenode = argv[0]; struct stat stab; cleanup_pkg_failed++; cleanup_conflictor_failed++; debug(dbg_eachfile, "cu_installnew '%s' flags=%o", namenode->name, namenode->flags); setupfnamevbs(namenode->name); if (!(namenode->flags & fnnf_new_conff) && !lstat(fnametmpvb.buf,&stab)) { /* OK, «pathname».dpkg-tmp exists. Remove «pathname» and * restore «pathname».dpkg-tmp ... */ if (namenode->flags & fnnf_no_atomic_overwrite) { /* If we can't do an atomic overwrite we have to delete first any * link to the new version we may have created. */ debug(dbg_eachfiledetail,"cu_installnew restoring nonatomic"); if (secure_remove(fnamevb.buf) && errno != ENOENT && errno != ENOTDIR) ohshite(_("unable to remove newly-installed version of '%.250s' to allow" " reinstallation of backup copy"),namenode->name); } else { debug(dbg_eachfiledetail,"cu_installnew restoring atomic"); } /* Either we can do an atomic restore, or we've made room: */ if (rename(fnametmpvb.buf,fnamevb.buf)) ohshite(_("unable to restore backup version of '%.250s'"), namenode->name); /* If «pathname».dpkg-tmp was still a hard link to «pathname», then the * atomic rename did nothing, so we make sure to remove the backup. */ else if (unlink(fnametmpvb.buf) && errno != ENOENT) ohshite(_("unable to remove backup copy of '%.250s'"), namenode->name); } else if (namenode->flags & fnnf_placed_on_disk) { debug(dbg_eachfiledetail,"cu_installnew removing new file"); if (secure_remove(fnamevb.buf) && errno != ENOENT && errno != ENOTDIR) ohshite(_("unable to remove newly-installed version of '%.250s'"), namenode->name); } else { debug(dbg_eachfiledetail,"cu_installnew not restoring"); } /* Whatever, we delete «pathname».dpkg-new now, if it still exists. */ if (secure_remove(fnamenewvb.buf) && errno != ENOENT && errno != ENOTDIR) ohshite(_("unable to remove newly-extracted version of '%.250s'"), namenode->name); cleanup_pkg_failed--; cleanup_conflictor_failed--; }