Commit 5a8e966f authored by Bernhard Link's avatar Bernhard Link

also package inclusion will automatically delete files losing the last reference

parent 0f014183
2005-01-19 Bernhard R. Link <brlink@debian.org>
* now also include, includedeb, includedsc
and update will remove files which are no
longer needed due to newer versions available,
except when --keepunreferencedfiles is given.
2005-01-17 Bernhard R. Link <brlink@debian.org>
* remove short options -e -N -l -r -M -d -D -c -p -o
to make it more guessable (and reserving short options
......
......@@ -680,7 +680,7 @@ static retvalue changes_includefiles(filesdb filesdb,const char *filename,struct
return r;
}
static retvalue changes_includepkgs(const char *dbdir,references refs,filesdb filesdb,struct distribution *distribution,struct changes *changes,const struct overrideinfo *srcoverride,const struct overrideinfo *binoverride,int force) {
static retvalue changes_includepkgs(const char *dbdir,references refs,filesdb filesdb,struct distribution *distribution,struct changes *changes,const struct overrideinfo *srcoverride,const struct overrideinfo *binoverride,int force,struct strlist *dereferencedfilekeys) {
struct fileentry *e;
retvalue r;
bool_t somethingwasmissed = FALSE;
......@@ -705,7 +705,7 @@ static retvalue changes_includepkgs(const char *dbdir,references refs,filesdb fi
distribution,fullfilename,
e->filekey,e->md5sum,
binoverride,
force,D_INPLACE);
force,D_INPLACE,dereferencedfilekeys);
if( r == RET_NOTHING )
somethingwasmissed = TRUE;
} else if( e->type == fe_UDEB ) {
......@@ -716,7 +716,7 @@ static retvalue changes_includepkgs(const char *dbdir,references refs,filesdb fi
distribution,fullfilename,
e->filekey,e->md5sum,
binoverride,
force,D_INPLACE);
force,D_INPLACE,dereferencedfilekeys);
if( r == RET_NOTHING )
somethingwasmissed = TRUE;
} else if( e->type == fe_DSC ) {
......@@ -728,7 +728,7 @@ static retvalue changes_includepkgs(const char *dbdir,references refs,filesdb fi
e->filekey,e->basename,
changes->srcdirectory,e->md5sum,
srcoverride,
force,D_INPLACE);
force,D_INPLACE,dereferencedfilekeys);
if( r == RET_NOTHING )
somethingwasmissed = TRUE;
}
......@@ -748,7 +748,7 @@ static retvalue changes_includepkgs(const char *dbdir,references refs,filesdb fi
/* insert the given .changes into the mirror in the <distribution>
* if forcecomponent, forcesection or forcepriority is NULL
* get it from the files or try to guess it. */
retvalue changes_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,struct distribution *distribution,const struct overrideinfo *srcoverride,const struct overrideinfo *binoverride,const char *changesfilename,int force,int delete) {
retvalue changes_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,struct distribution *distribution,const struct overrideinfo *srcoverride,const struct overrideinfo *binoverride,const char *changesfilename,int force,int delete,struct strlist *dereferencedfilekeys) {
retvalue r;
struct changes *changes;
......@@ -788,7 +788,7 @@ retvalue changes_add(const char *dbdir,references refs,filesdb filesdb,const cha
/* add the source and binary packages in the given distribution */
r = changes_includepkgs(dbdir,refs,filesdb,
distribution,changes,srcoverride,binoverride,force);
distribution,changes,srcoverride,binoverride,force,dereferencedfilekeys);
if( RET_WAS_ERROR(r) ) {
changes_free(changes);
return r;
......
......@@ -14,8 +14,9 @@
/* insert the given .changes into the mirror in the <distribution>
* if forcecomponent, forcesection or forcepriority is NULL
* get it from the files or try to guess it. */
retvalue changes_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,struct distribution *distribution,const struct overrideinfo *srcoverride,const struct overrideinfo *binoverride,const char *changesfilename,int force,int delete);
* get it from the files or try to guess it.
* if dereferencedfilekeys is != NULL, add filekeys that lost reference */
retvalue changes_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,struct distribution *distribution,const struct overrideinfo *srcoverride,const struct overrideinfo *binoverride,const char *changesfilename,int force,int delete,struct strlist *dereferencedfilkekeys);
#endif
......@@ -294,7 +294,7 @@ static retvalue deb_checkfiles(filesdb filesdb,struct debpackage *pkg,const char
* causing error, if it is not one of them otherwise)
* if component is NULL, guessing it from the section. */
retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,const char *suffix,struct distribution *distribution,const char *debfilename,const char *givenfilekey,const char *givenmd5sum,const struct overrideinfo *binoverride,int force,int delete){
retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,const char *suffix,struct distribution *distribution,const char *debfilename,const char *givenfilekey,const char *givenmd5sum,const struct overrideinfo *binoverride,int force,int delete,struct strlist *dereferencedfilekeys){
retvalue r,result;
struct debpackage *pkg;
const struct overrideinfo *oinfo;
......@@ -435,7 +435,7 @@ retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *f
r = target_initpackagesdb(t,dbdir);
if( !RET_WAS_ERROR(r) ) {
retvalue r2;
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE);
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE,dereferencedfilekeys);
r2 = target_closepackagesdb(t);
RET_ENDUPDATE(r,r2);
}
......@@ -445,7 +445,7 @@ retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *f
r = target_initpackagesdb(t,dbdir);
if( !RET_WAS_ERROR(r) ) {
retvalue r2;
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE);
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE,dereferencedfilekeys);
r2 = target_closepackagesdb(t);
RET_ENDUPDATE(r,r2);
}
......@@ -458,7 +458,7 @@ retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *f
r = target_initpackagesdb(t,dbdir);
if( !RET_WAS_ERROR(r) ) {
retvalue r2;
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE);
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE,dereferencedfilekeys);
r2 = target_closepackagesdb(t);
RET_ENDUPDATE(r,r2);
}
......
......@@ -20,6 +20,7 @@
* causing error, if it is not one of them otherwise)
* if overwrite is not NULL, it will be search for fields to reset for this
* package. (forcesection and forcepriority have higher priority than the
* information there) */
retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,const char *suffix,struct distribution *distribution,const char *debfilename,const char *givenfilekey,const char *givenmd5sum,const struct overrideinfo *override,int force,int delete);
* information there),
* if dereferencedfilekeys is != NULL, add there filekeys that lost a reference */
retvalue deb_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcearchitecture,const char *forcesection,const char *forcepriority,const char *suffix,struct distribution *distribution,const char *debfilename,const char *givenfilekey,const char *givenmd5sum,const struct overrideinfo *binoverride,int force,int delete,struct strlist *dereferencedfilekeys);
#endif
......@@ -374,7 +374,7 @@ static retvalue dsc_checkfiles(filesdb filesdb,
* of beeing newly calculated.
* (And all files are expected to already be in the pool). */
retvalue dsc_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcesection,const char *forcepriority,struct distribution *distribution,const char *dscfilename,const char *filekey,const char *basename,const char *directory,const char *md5sum,const struct overrideinfo *srcoverride,int force,int delete){
retvalue dsc_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcesection,const char *forcepriority,struct distribution *distribution,const char *dscfilename,const char *filekey,const char *basename,const char *directory,const char *md5sum,const struct overrideinfo *srcoverride,int force,int delete,struct strlist *dereferencedfilekeys){
retvalue r;
struct dscpackage *pkg;
const struct overrideinfo *oinfo;
......@@ -472,7 +472,7 @@ retvalue dsc_add(const char *dbdir,references refs,filesdb filesdb,const char *f
r = target_initpackagesdb(t,dbdir);
if( !RET_WAS_ERROR(r) ) {
retvalue r2;
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE);
r = target_addpackage(t,refs,pkg->package,pkg->version,pkg->control,&pkg->filekeys,force,FALSE,dereferencedfilekeys);
r2 = target_closepackagesdb(t);
RET_ENDUPDATE(r,r2);
}
......
......@@ -19,7 +19,8 @@
* if component is NULL, guess it from the section.
* If basename, filekey and directory are != NULL, then they are used instead
* of beeing newly calculated.
* (And all files are expected to already be in the pool). */
retvalue dsc_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcesection,const char *forcepriority,struct distribution *distribution,const char *dscfilename,const char *filekey,const char *basename,const char *directory,const char *md5sum,const struct overrideinfo *srcoverride,int force,int delete);
* (And all files are expected to already be in the pool),
* if dereferenced_filekeys is != NULL, add there the filekeys that lost a reference*/
retvalue dsc_add(const char *dbdir,references refs,filesdb filesdb,const char *forcecomponent,const char *forcesection,const char *forcepriority,struct distribution *distribution,const char *dscfilename,const char *filekey,const char *basename,const char *directory,const char *md5sum,const struct overrideinfo *srcoverride,int force,int delete,struct strlist *derefencedfilekeys);
#endif
......@@ -174,7 +174,6 @@ retvalue files_deleteandremove(filesdb filesdb,const char *filekey) {
if( !filename )
return RET_ERROR_OOM;
err = unlink(filename);
free(filename);
if( err != 0 ) {
en = errno;
r = RET_ERRNO(en);
......@@ -182,9 +181,11 @@ retvalue files_deleteandremove(filesdb filesdb,const char *filekey) {
fprintf(stderr,"%s not found, forgetting anyway\n",filename);
} else {
fprintf(stderr,"error while unlinking %s: %m(%d)\n",filename,en);
free(filename);
return r;
}
}
free(filename);
r = files_remove(filesdb,filekey);
return r;
}
......
......@@ -76,6 +76,44 @@ static bool_t nolistsdownload = FALSE;
static bool_t keepunreferenced = FALSE;
int verbose = 0;
static inline retvalue removeunreferencedfiles(references refs,filesdb files,struct strlist *dereferencedfilekeys) {
int i;
retvalue result,r;
result = RET_OK;
for( i = 0 ; i < dereferencedfilekeys->count ; i++ ) {
const char *filekey = dereferencedfilekeys->values[i];
r = references_isused(refs,filekey);
if( r == RET_NOTHING ) {
r = files_deleteandremove(files,filekey);
}
RET_UPDATE(result,r);
}
return result;
}
static inline retvalue possiblyremoveunreferencedfilekeys(retvalue result,
references refs,filesdb files,struct strlist *dereferencedfilekeys) {
retvalue r;
if( !keepunreferenced && dereferencedfilekeys->count > 0 ) {
if( RET_IS_OK(result) ) {
if( verbose >= 0 )
fprintf(stderr,"Deleting files no longer referenced...\n");
r = removeunreferencedfiles(refs,files,dereferencedfilekeys);
RET_UPDATE(result,r);
} else {
fprintf(stderr,
"Not deleting possibly left over files due to previous errors.\n"
"(To avoid the files in the still existing index files vanishing)\n"
"Use dumpunreferenced/deleteunreferenced to show/delete files without referenes.\n");
}
}
strlist_done(dereferencedfilekeys);
return result;
}
static retvalue action_printargs(int argc,const char *argv[]) {
int i;
......@@ -358,21 +396,14 @@ static retvalue action_remove(int argc,const char *argv[]) {
r = files_initialize(&files,dbdir,mirrordir);
RET_ENDUPDATE(result,r);
if( RET_IS_OK(r) ) {
int i;
for( i = 0 ; i < d.removedfiles.count ; i++ ) {
const char *filekey = d.removedfiles.values[i];
r = references_isused(d.refs,filekey);
if( r == RET_NOTHING ) {
r = files_deleteandremove(files,filekey);
}
RET_ENDUPDATE(result,r);
}
r = removeunreferencedfiles(d.refs,files,&d.removedfiles);
RET_ENDUPDATE(result,r);
r = files_done(files);
RET_ENDUPDATE(result,r);
} else {
strlist_done(&d.removedfiles);
}
}
strlist_done(&d.removedfiles);
r = references_done(d.refs);
RET_ENDUPDATE(result,r);
if( verbose >= 0 && !RET_WAS_ERROR(result) && d.todo > 0 ) {
......@@ -596,6 +627,7 @@ static retvalue action_update(int argc,const char *argv[]) {
struct update_pattern *patterns;
struct distribution *distributions;
filesdb files;
struct strlist dereferencedfilekeys;
if( argc < 1 ) {
fprintf(stderr,"reprepro update [<distributions>]\n");
......@@ -606,6 +638,10 @@ static retvalue action_update(int argc,const char *argv[]) {
if( RET_WAS_ERROR(result) ) {
return result;
}
result = strlist_init(&dereferencedfilekeys);
if( RET_WAS_ERROR(result) ) {
return result;
}
result = distribution_getmatched(confdir,argc-1,argv+1,&distributions);
if( RET_WAS_ERROR(result) )
......@@ -632,11 +668,8 @@ static retvalue action_update(int argc,const char *argv[]) {
return result;
}
result = updates_update(dbdir,methoddir,files,refs,distributions,force,nolistsdownload);
result = updates_update(dbdir,methoddir,files,refs,distributions,force,nolistsdownload,keepunreferenced?NULL:&dereferencedfilekeys);
r = files_done(files);
RET_ENDUPDATE(result,r);
doexport = force>0 || RET_IS_OK(result);
if( doexport && verbose >= 0 )
fprintf(stderr,"Exporting indices...\n");
......@@ -651,9 +684,12 @@ static retvalue action_update(int argc,const char *argv[]) {
(void)distribution_free(distributions);
distributions = d;
}
result = possiblyremoveunreferencedfilekeys(result,refs,files,&dereferencedfilekeys);
r = references_done(refs);
RET_ENDUPDATE(result,r);
r = files_done(files);
RET_ENDUPDATE(result,r);
return result;
}
......@@ -846,11 +882,16 @@ static retvalue action_includedeb(int argc,const char *argv[]) {
filesdb files;references refs;
struct distribution *distribution;
struct overrideinfo *override;
struct strlist dereferencedfilekeys;
if( argc < 3 ) {
fprintf(stderr,"reprepro [--delete] includedeb <distribution> <package>\n");
return RET_ERROR;
}
result = strlist_init(&dereferencedfilekeys);
if( RET_WAS_ERROR(result) ) {
return result;
}
result = distribution_get(&distribution,confdir,argv[1]);
if( RET_WAS_ERROR(result) ) {
......@@ -889,13 +930,15 @@ static retvalue action_includedeb(int argc,const char *argv[]) {
}
result = deb_add(dbdir,refs,files,component,architecture,
section,priority,"deb",distribution,argv[2],NULL,NULL,override,force,delete);
section,priority,"deb",distribution,argv[2],NULL,NULL,override,force,delete,keepunreferenced?NULL:&dereferencedfilekeys);
override_free(override);
r = distribution_export(distribution,dbdir,distdir,force,TRUE);
RET_ENDUPDATE(result,r);
result = possiblyremoveunreferencedfilekeys(result,refs,files,&dereferencedfilekeys);
r = distribution_free(distribution);
RET_ENDUPDATE(result,r);
r = files_done(files);
......@@ -912,6 +955,7 @@ static retvalue action_includedsc(int argc,const char *argv[]) {
filesdb files; references refs;
struct distribution *distribution;
struct overrideinfo *srcoverride;
struct strlist dereferencedfilekeys;
if( argc < 3 ) {
fprintf(stderr,"reprepro [--delete] includedsc <distribution> <package>\n");
......@@ -923,6 +967,11 @@ static retvalue action_includedsc(int argc,const char *argv[]) {
return RET_ERROR;
}
result = strlist_init(&dereferencedfilekeys);
if( RET_WAS_ERROR(result) ) {
return result;
}
result = distribution_get(&distribution,confdir,argv[1]);
if( RET_WAS_ERROR(result) )
return result;
......@@ -949,13 +998,16 @@ static retvalue action_includedsc(int argc,const char *argv[]) {
return r;
}
result = dsc_add(dbdir,refs,files,component,section,priority,distribution,argv[2],NULL,NULL,NULL,NULL,srcoverride,force,delete);
result = dsc_add(dbdir,refs,files,component,section,priority,distribution,argv[2],NULL,NULL,NULL,NULL,srcoverride,force,delete,keepunreferenced?NULL:&dereferencedfilekeys);
override_free(srcoverride);
r = distribution_export(distribution,dbdir,distdir,force,TRUE);
RET_ENDUPDATE(result,r);
r = distribution_free(distribution);
RET_ENDUPDATE(result,r);
result = possiblyremoveunreferencedfilekeys(result,refs,files,&dereferencedfilekeys);
r = files_done(files);
RET_ENDUPDATE(result,r);
r = references_done(refs);
......@@ -969,11 +1021,16 @@ static retvalue action_include(int argc,const char *argv[]) {
filesdb files;references refs;
struct distribution *distribution;
struct overrideinfo *override,*srcoverride;
struct strlist dereferencedfilekeys;
if( argc < 3 ) {
fprintf(stderr,"reprepro [--delete] include <distribution> <.changes-file>\n");
return RET_ERROR;
}
result = strlist_init(&dereferencedfilekeys);
if( RET_WAS_ERROR(result) ) {
return result;
}
result = distribution_get(&distribution,confdir,argv[1]);
if( RET_WAS_ERROR(result) )
......@@ -1010,7 +1067,7 @@ static retvalue action_include(int argc,const char *argv[]) {
return r;
}
result = changes_add(dbdir,refs,files,component,architecture,section,priority,distribution,srcoverride,override,argv[2],force,delete);
result = changes_add(dbdir,refs,files,component,architecture,section,priority,distribution,srcoverride,override,argv[2],force,delete,keepunreferenced?NULL:&dereferencedfilekeys);
override_free(override);override_free(srcoverride);
......@@ -1018,6 +1075,9 @@ static retvalue action_include(int argc,const char *argv[]) {
RET_ENDUPDATE(result,r);
r = distribution_free(distribution);
RET_ENDUPDATE(result,r);
result = possiblyremoveunreferencedfilekeys(result,refs,files,&dereferencedfilekeys);
r = files_done(files);
RET_ENDUPDATE(result,r);
r = references_done(refs);
......
......@@ -362,7 +362,8 @@ retvalue packages_export(packagesdb packagesdb,const char *filename,indexcompres
retvalue packages_insert(references refs, packagesdb packagesdb,
const char *packagename, const char *controlchunk,
const struct strlist *files,
const struct strlist *oldfiles) {
struct strlist *oldfiles,
struct strlist *dereferencedfilekeys) {
retvalue result,r;
......@@ -371,8 +372,11 @@ retvalue packages_insert(references refs, packagesdb packagesdb,
r = references_insert(refs,packagesdb->identifier,files,oldfiles);
if( RET_WAS_ERROR(r) )
if( RET_WAS_ERROR(r) ) {
if( oldfiles )
strlist_done(oldfiles);
return r;
}
/* Add package to the distribution's database */
......@@ -383,14 +387,17 @@ retvalue packages_insert(references refs, packagesdb packagesdb,
result = packages_add(packagesdb,packagename,controlchunk);
}
if( RET_WAS_ERROR(result) )
if( RET_WAS_ERROR(result) ) {
if( oldfiles )
strlist_done(oldfiles);
return result;
}
/* remove old references to files */
if( oldfiles != NULL ) {
r = references_delete(refs,packagesdb->identifier,
oldfiles,files);
oldfiles,files,dereferencedfilekeys);
RET_UPDATE(result,r);
}
......
......@@ -41,11 +41,13 @@ retvalue packages_remove(packagesdb db,const char *package);
retvalue packages_get(packagesdb db,const char *package,char **chunk);
/* insert a chunk in the packages database, adding and deleting
* references and insert files while that. */
* references and insert files while that.
* free oldfiles, if != NULL, add filekeys losing reference to derferencedfilekeys*/
retvalue packages_insert(references refs, packagesdb packagesdb,
const char *packagename, const char *controlchunk,
const struct strlist *files,
const struct strlist *oldfiles);
struct strlist *oldfiles,
struct strlist *dereferencedfilekeys);
retvalue packages_export(packagesdb packagesdb,const char *filename,indexcompression compression);
......
......@@ -16,6 +16,7 @@
*/
#include <config.h>
#include <assert.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
......@@ -235,20 +236,31 @@ retvalue references_insert(references refs,const char *identifier,
/* Remove reference by <identifer> for the given <oldfiles>,
* excluding <exclude>, if it is nonNULL. */
retvalue references_delete(references refs,const char *identifier,
const struct strlist *files,const struct strlist *exclude) {
struct strlist *files,const struct strlist *exclude,
struct strlist *dereferencedfilekeys) {
retvalue result,r;
int i;
assert( files != NULL );
result = RET_NOTHING;
for( i = 0 ; i < files->count ; i++ ) {
const char *filename = files->values[i];
char *filekey = files->values[i];
files->values[i] = NULL;
if( exclude == NULL || !strlist_in(exclude,filename) ) {
r = references_decrement(refs,filename,identifier);
if( exclude == NULL || !strlist_in(exclude,filekey) ) {
r = references_decrement(refs,filekey,identifier);
RET_UPDATE(result,r);
}
if( RET_IS_OK(r) && dereferencedfilekeys ) {
r = strlist_adduniq(dereferencedfilekeys, filekey);
RET_UPDATE(result,r);
} else
free(filekey);
} else
free(filekey);
}
strlist_done(files);
return result;
}
......
......@@ -26,9 +26,12 @@ retvalue references_insert(references ref,const char *identifer,
const struct strlist *files,const struct strlist *exclude);
/* Remove reference by <identifer> for the given <oldfiles>,
* excluding <exclude>, if it is nonNULL. */
* excluding <exclude>, if it is nonNULL.
* if dereferencedfilekeys is != NULL, add those losing one reference,
* files will be freed (or moved to dereferencedfilekeys) */
retvalue references_delete(references ref,const char *identifer,
const struct strlist *files,const struct strlist *exclude);
struct strlist *files,const struct strlist *exclude,
struct strlist *dereferencedfilekeys);
/* add an reference to a file for an identifier. multiple calls
* will add multiple references to allow source packages to share
......
......@@ -223,3 +223,13 @@ retvalue strlist_mvadd(struct strlist *dest,struct strlist *orig) {
return RET_OK;
}
retvalue strlist_adduniq(struct strlist *strlist,char *element) {
// TODO: is there something better feasible?
if( strlist_in(strlist,element) ) {
free(element);
return RET_OK;
} else
return strlist_add(strlist,element);
}
......@@ -20,6 +20,8 @@ void strlist_done(struct strlist *strlist);
retvalue strlist_add(struct strlist *strlist,char *element);
/* include a string at the beginning, otherwise like strlist_add */
retvalue strlist_include(struct strlist *strlist,char *element);
/* add a string alphabetically, discarding if already there. */
retvalue strlist_adduniq(struct strlist *strlist,char *element);
/* print a space seperated list of elements */
retvalue strlist_fprint(FILE *file,const struct strlist *strlist);
......
......@@ -148,9 +148,9 @@ retvalue target_closepackagesdb(struct target *target) {
return r;
}
/* Remove a package from the given target. If removedfilekeys != NULL, add there the
/* Remove a package from the given target. If dereferencedfilekeys != NULL, add there the
* filekeys that lost references */
retvalue target_removepackage(struct target *target,references refs,const char *name, struct strlist *removedfilekeys) {
retvalue target_removepackage(struct target *target,references refs,const char *name, struct strlist *dereferencedfilekeys) {
char *oldchunk;
struct strlist files;
retvalue r;
......@@ -158,8 +158,9 @@ retvalue target_removepackage(struct target *target,references refs,const char *
assert(target && target->packages && name);
r = packages_get(target->packages,name,&oldchunk);
if( RET_WAS_ERROR(r) )
if( RET_WAS_ERROR(r) ) {
return r;
}
else if( r == RET_NOTHING ) {
if( verbose >= 10 )
fprintf(stderr,"Could not find '%s' in '%s'...\n",
......@@ -176,19 +177,13 @@ retvalue target_removepackage(struct target *target,references refs,const char *
r = packages_remove(target->packages,name);
if( RET_IS_OK(r) ) {
target->wasmodified = TRUE;
r = references_delete(refs,target->identifier,&files,NULL);
}
if( removedfilekeys != NULL ) {
retvalue r2 = strlist_mvadd(removedfilekeys,&files);
if( RET_WAS_ERROR(r2) )
strlist_done(&files);
} else {
r = references_delete(refs,target->identifier,&files,NULL,dereferencedfilekeys);
} else
strlist_done(&files);
}
return r;
}
retvalue target_addpackage(struct target *target,references refs,const char *name,const char *version,const char *control,const struct strlist *filekeys,int force,bool_t downgrade) {
retvalue target_addpackage(struct target *target,references refs,const char *name,const char *version,const char *control,const struct strlist *filekeys,int force,bool_t downgrade, struct strlist *dereferencedfilekeys) {
struct strlist oldfilekeys,*ofk;
char *oldcontrol;
retvalue r;
......@@ -245,12 +240,10 @@ retvalue target_addpackage(struct target *target,references refs,const char *nam
return r;
}
}
r = packages_insert(refs,target->packages,name,control,filekeys,ofk);
r = packages_insert(refs,target->packages,name,control,filekeys,ofk,dereferencedfilekeys);
if( RET_IS_OK(r) )
target->wasmodified = TRUE;
if( ofk )
strlist_done(ofk);
return r;
}
......
......@@ -62,8 +62,8 @@ retvalue target_closepackagesdb(struct target *target);
/* The following calls can only be called if target_initpackagesdb was called before: */
retvalue target_addpackage(struct target *target,references refs,const char *name,const char *version,const char *control,const struct strlist *filekeys,int force,bool_t downgrade);
retvalue target_removepackage(struct target *target,references refs,const char *name, struct strlist *removedfilekeys);
retvalue target_addpackage(struct target *target,references refs,const char *name,const char *version,const char *control,const struct strlist *filekeys,int force,bool_t downgrade,struct strlist *dereferencedfilekeys);
retvalue target_removepackage(struct target *target,references refs,const char *name, struct strlist *dereferencedfilekeys);
retvalue target_writeindices(struct target *target,const char *distdir, int force,bool_t onlyneeded);
retvalue target_check(struct target *target,filesdb filesdb,references refsdb,int force);
retvalue target_rereference(struct target *target,references refs,int force);
......
......@@ -1099,13 +1099,13 @@ static retvalue updates_enqueue(const char *dbdir,struct downloadcache *cache,fi
}
static retvalue updates_install(const char *dbdir,filesdb filesdb,references refs,struct distribution *distribution,int force) {
static retvalue updates_install(const char *dbdir,filesdb filesdb,references refs,struct distribution *distribution,int force,struct strlist *dereferencedfilekeys) {
retvalue result,r;
struct update_target *u;
result = RET_NOTHING;
for( u=distribution->updatetargets ; u ; u=u->next ) {
r = upgradelist_install(u->upgradelist,dbdir,filesdb,refs,force,u->ignoredelete);
r = upgradelist_install(u->upgradelist,dbdir,filesdb,refs,force,u->ignoredelete,dereferencedfilekeys);
RET_UPDATE(result,r);
upgradelist_free(u->upgradelist);
u->upgradelist = NULL;
......@@ -1154,7 +1154,7 @@ static retvalue updates_downloadlists(const char *methoddir,struct aptmethodrun
return result;
}
retvalue updates_update(const char *dbdir,const char *methoddir,filesdb filesdb,references refs,struct distribution *distributions,int force,bool_t nolistdownload) {
retvalue updates_update(const char *dbdir,const char *methoddir,filesdb filesdb,references refs,struct distribution *distributions,int force,bool_t nolistdownload,struct strlist *dereferencedfilekeys) {
retvalue result,r;
struct distribution *distribution;
struct aptmethodrun *run;
......@@ -1223,7 +1223,7 @@ retvalue updates_update(const char *dbdir,const char *methoddir,filesdb filesdb,
fprintf(stderr,"Installing (and possibly deleting) packages...\n");
for( distribution=distributions ; distribution ; distribution=distribution->next) {
r = updates_install(dbdir,filesdb,refs,distribution,force);
r = updates_install(dbdir,filesdb,refs,distribution,force,dereferencedfilekeys);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && ! force )
break;
......
......@@ -21,7 +21,7 @@ void updates_freetargets(struct update_target *t);
retvalue updates_calcindices(const char *listdir,const struct update_pattern *patterns,struct distribution *distributions);
retvalue updates_update(const char *dbdir,const char *methoddir,filesdb filesdb,references refs,struct distribution *distributions,int force,bool_t nolistdownload);
retvalue updates_update(const char *dbdir,const char *methoddir,filesdb filesdb,references refs,struct distribution *distributions,int force,bool_t nolistdownload,struct strlist *dereferencedfilekeys);
retvalue updates_checkupdate(const char *dbdir,const char *methoddir,struct distribution *distributions,int force,bool_t nolistdownload);
#endif
......@@ -478,7 +478,7 @@ retvalue upgradelist_enqueue(struct upgradelist *upgrade,struct downloadcache *c
return result;
}
retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,filesdb files,references refs,int force, bool_t ignoredelete){
retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,filesdb files,references refs,int force, bool_t ignoredelete, struct strlist *dereferencedfilekeys){
struct package_data *pkg;
retvalue result,r;
......@@ -496,13 +496,13 @@ retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,files
/* upgrade (or possibly downgrade) */
r = target_addpackage(upgrade->target,refs,
pkg->name,pkg->new_version,pkg->new_control,
&pkg->new_filekeys,force,TRUE);
&pkg->new_filekeys,force,TRUE,dereferencedfilekeys);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && !force )
break;
}
if( pkg->deleted && pkg->version_in_use != NULL && !ignoredelete ) {
r = target_removepackage(upgrade->target,refs,pkg->name,NULL);
r = target_removepackage(upgrade->target,refs,pkg->name,dereferencedfilekeys);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && !force )
break;
......
......@@ -43,6 +43,6 @@ retvalue upgradelist_deleteall(struct upgradelist *upgrade);
/* request all wanted files refering the methods given before */
retvalue upgradelist_enqueue(struct upgradelist *upgrade,struct downloadcache *cache,filesdb filesdb,int force);
retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,filesdb files,references refs,int force, bool_t ignoredelete);
retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,filesdb files,references refs,int force, bool_t ignoredelete, struct strlist *dereferencedfilekeys);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment