Chapter 14. System Repository

Table of Contents

1. FileStore
2. HashDir
2.1. Commit
3. gdbm
4. gdbm::ResourceDB
5. ResourceDB::gdbm
6. Repository::System
7. Committing the repository

Section 6, “Repositories” introduces the concept of a Repository, which is an object that describes a collection of packages. The System Repository is a database that implements a repository of packages installed by LPMtool. This chapter describes how the System Repository database is implemented.

1. FileStore

The FileStore object represents an arbitrary collection of files. Files are not accessed directly, but through the FileStore object. These files are expected to be comparatively small. The contents of each file are requested individually. The FileStore maintains an internal cache. The first time a file is read, it is saved in the cache. Subsequent requests for the same file will use the cached copy of the file's contents.

In other words: FileStore functions as a caching layer between LPMtool, and the actual files. The FileStore object defines the following methods:


Return the contents of the file, as a string. If the file's contents are already cached, used the cached copy. If not, invoke the fget() function. fget must be defined by FileStore's subclass. fget opens the file and reads its contents (or return an empty string if the file does not exist).

update, remove

These methods update the contents of a file, or remove it. These methods do not actually make any changes, they only update FileStore's internal cache to reflect these changes. Subsequent calls to get and enumerate reflect these changes.


Enumerate all files in the FileStore. This method invokes the fenumerate method, which must be defined by the subclass to return the list of files in the collection. The list of files returned by fenumerate is modified according to the contents of FileStore's internal cache. That is, files returned by fenumerate which have been removed are suppressed; and new files added via update are also included in the list returned by enumerate.

enumerate's output reflects the underlying collection of files, with all changes specified by prior updates and removes applied.

A FileStore is just a caching layer that also reflects changes to the collection of files it represents. The job of updating the actual files is left to the subclass. The FileStore object implements a virtual caching layer that keeps track of the changes to collection of files it represents.