diff options
Diffstat (limited to 'src/filesdb.c')
-rw-r--r-- | src/filesdb.c | 209 |
1 files changed, 0 insertions, 209 deletions
diff --git a/src/filesdb.c b/src/filesdb.c index 6e99c36f3..87bca58e3 100644 --- a/src/filesdb.c +++ b/src/filesdb.c @@ -54,47 +54,9 @@ #include "infodb.h" #include "main.h" -/*** filepackages support for tracking packages owning a file. ***/ - -struct filepackages_iterator { - struct pkg_list *pkg_node; -}; - -struct filepackages_iterator * -filepackages_iter_new(struct filenamenode *fnn) -{ - struct filepackages_iterator *iter; - - iter = m_malloc(sizeof(*iter)); - iter->pkg_node = fnn->packages; - - return iter; -} - -struct pkginfo * -filepackages_iter_next(struct filepackages_iterator *iter) -{ - struct pkg_list *pkg_node; - - if (iter->pkg_node == NULL) - return NULL; - - pkg_node = iter->pkg_node; - iter->pkg_node = pkg_node->next; - - return pkg_node->pkg; -} - -void -filepackages_iter_free(struct filepackages_iterator *iter) -{ - free(iter); -} - /*** Generic data structures and routines. ***/ static bool allpackagesdone = false; -static int nfiles= 0; void ensure_package_clientdata(struct pkginfo *pkg) @@ -473,174 +435,3 @@ write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin, note_must_reread_files_inpackage(pkg); } - -/* - * Initializes an iterator that appears to go through the file - * list ‘files’ in reverse order, returning the namenode from - * each. What actually happens is that we walk the list here, - * building up a reverse list, and then peel it apart one - * entry at a time. - */ -void -reversefilelist_init(struct reversefilelistiter *iter, struct fileinlist *files) -{ - struct fileinlist *newent; - - iter->todo = NULL; - while (files) { - newent= m_malloc(sizeof(struct fileinlist)); - newent->namenode= files->namenode; - newent->next = iter->todo; - iter->todo = newent; - files= files->next; - } -} - -struct filenamenode * -reversefilelist_next(struct reversefilelistiter *iter) -{ - struct filenamenode *ret; - struct fileinlist *todo; - - todo = iter->todo; - if (!todo) - return NULL; - ret= todo->namenode; - iter->todo = todo->next; - free(todo); - return ret; -} - -/* - * Clients must call this function to clean up the reversefilelistiter - * if they wish to break out of the iteration before it is all done. - * Calling this function is not necessary if reversefilelist_next has - * been called until it returned 0. - */ -void -reversefilelist_abort(struct reversefilelistiter *iter) -{ - while (reversefilelist_next(iter)); -} - -struct fileiterator { - struct filenamenode *namenode; - int nbinn; -}; - -/* This must always be a prime for optimal performance. - * This is the closest one to 2^18 (262144). */ -#define BINS 262139 - -static struct filenamenode *bins[BINS]; - -struct fileiterator * -files_db_iter_new(void) -{ - struct fileiterator *iter; - - iter = m_malloc(sizeof(struct fileiterator)); - iter->namenode = NULL; - iter->nbinn = 0; - - return iter; -} - -struct filenamenode * -files_db_iter_next(struct fileiterator *iter) -{ - struct filenamenode *r= NULL; - - while (!iter->namenode) { - if (iter->nbinn >= BINS) - return NULL; - iter->namenode = bins[iter->nbinn++]; - } - r = iter->namenode; - iter->namenode = r->next; - - return r; -} - -void -files_db_iter_free(struct fileiterator *iter) -{ - free(iter); -} - -void filesdbinit(void) { - struct filenamenode *fnn; - int i; - - for (i=0; i<BINS; i++) - for (fnn= bins[i]; fnn; fnn= fnn->next) { - fnn->flags= 0; - fnn->oldhash = NULL; - fnn->newhash = EMPTYHASHFLAG; - fnn->filestat = NULL; - } -} - -void -files_db_reset(void) -{ - int i; - - for (i = 0; i < BINS; i++) - bins[i] = NULL; -} - -int -fsys_hash_entries(void) -{ - return nfiles; -} - -struct filenamenode *findnamenode(const char *name, enum fnnflags flags) { - struct filenamenode **pointerp, *newnode; - const char *orig_name = name; - - /* We skip initial slashes and ‘./’ pairs, and add our own single - * leading slash. */ - name = path_skip_slash_dotslash(name); - - pointerp = bins + (str_fnv_hash(name) % (BINS)); - while (*pointerp) { - /* XXX: This should not be needed, but it has been a constant source - * of assertions over the years. Hopefully with the internerr() we will - * get better diagnostics. */ - if ((*pointerp)->name[0] != '/') - internerr("filename node '%s' does not start with '/'", - (*pointerp)->name); - - if (strcmp((*pointerp)->name + 1, name) == 0) - break; - pointerp= &(*pointerp)->next; - } - if (*pointerp) return *pointerp; - - if (flags & fnn_nonew) - return NULL; - - newnode= nfmalloc(sizeof(struct filenamenode)); - newnode->packages = NULL; - if((flags & fnn_nocopy) && name > orig_name && name[-1] == '/') - newnode->name = name - 1; - else { - char *newname= nfmalloc(strlen(name)+2); - newname[0]= '/'; strcpy(newname+1,name); - newnode->name= newname; - } - newnode->flags= 0; - newnode->next = NULL; - newnode->divert = NULL; - newnode->statoverride = NULL; - newnode->oldhash = NULL; - newnode->newhash = EMPTYHASHFLAG; - newnode->filestat = NULL; - newnode->trig_interested = NULL; - *pointerp= newnode; - nfiles++; - - return newnode; -} |