Package portage :: Package dbapi :: Module vartree :: Class dblink
[hide private]

Class dblink

source code

object --+
         |
        dblink

This class provides an interface to the installed package database At present this is implemented as a text backend in /var/db/pkg.

Instance Methods [hide private]
 
__init__(self, cat, pkg, myroot=None, settings=None, treetype=None, vartree=None, blockers=None, scheduler=None, pipe=None)
Creates a DBlink object for a given CPV.
source code
 
__hash__(self)
hash(x)
source code
 
__eq__(self, other) source code
 
_get_protect_obj(self) source code
 
isprotected(self, obj) source code
 
updateprotect(self) source code
 
lockdb(self) source code
 
unlockdb(self) source code
 
getpath(self)
return path to location of db information (for >>> informational display)
source code
 
exists(self)
does the db entry exist? boolean.
source code
 
delete(self)
Remove this entry from the database
source code
 
clearcontents(self)
For a given db entry (self), erase the CONTENTS values.
source code
 
_clear_contents_cache(self) source code
 
getcontents(self)
Get the installed files of a given package (aka what that package installed)
source code
 
_prune_plib_registry(self, unmerge=False, needed=None, preserve_paths=None) source code
 
unmerge(self, pkgfiles=None, trimworld=None, cleanup=True, ldpath_mtimes=None, others_in_slot=None, needed=None, preserve_paths=None)
Calls prerm Unmerges a given package (CPV) calls postrm calls cleanrm calls env_update
source code
 
_display_merge(self, msg, level=0, noiselevel=0) source code
 
_show_unmerge(self, zing, desc, file_type, file_name) source code
None
_unmerge_pkgfiles(self, pkgfiles, others_in_slot)
Unmerges the contents of a package from the liveFS Removes the VDB entry for self
source code
 
_unmerge_protected_symlinks(self, others_in_slot, infodirs_inodes, protected_symlinks, unmerge_desc, unlink, os) source code
 
_unmerge_dirs(self, dirs, infodirs_inodes, protected_symlinks, unmerge_desc, unlink, os) source code
 
isowner(self, filename, destroot=None)
Check if a file belongs to this package.
source code
String
_match_contents(self, filename, destroot=None)
The matching contents entry is returned, which is useful since the path may differ from the one given by the caller, due to symlinks.
source code
 
_linkmap_rebuild(self, **kwargs)
Rebuild the self._linkmap if it's not broken due to missing scanelf binary.
source code
 
_find_libs_to_preserve(self, unmerge=False)
Get set of relative paths for libraries to be preserved.
source code
 
_add_preserve_libs_to_contents(self, preserve_paths)
Preserve libs returned from _find_libs_to_preserve().
source code
 
_find_unused_preserved_libs(self, unmerge_no_replacement)
Find preserved libraries that don't have any consumers left.
source code
 
_remove_preserved_libs(self, cpv_lib_map)
Remove files returned from _find_unused_preserved_libs().
source code
 
_collision_protect(self, srcroot, destroot, mypkglist, file_list, symlink_list) source code
 
_lstat_inode_map(self, path_iter)
Use lstat to create a map of the form: {(st_dev, st_ino) : set([path1, path2, ...])} Multiple paths may reference the same inode due to hardlinks.
source code
 
_security_check(self, installed_instances) source code
 
_eqawarn(self, phase, lines) source code
 
_eerror(self, phase, lines) source code
 
_elog(self, funcname, phase, lines) source code
 
_elog_process(self, phasefilter=None) source code
 
_emerge_log(self, msg) source code
 
treewalk(self, srcroot, destroot, inforoot, myebuild, cleanup=0, mydbapi=None, prev_mtimes=None, counter=None)
This function does the following:
source code
 
_new_backup_path(self, p)
The works for any type path, such as a regular file, symlink, or directory.
source code
 
_merge_contents(self, srcroot, destroot, cfgfiledict) source code
 
mergeme(self, srcroot, destroot, outfile, secondhand, stufftomerge, cfgfiledict, thismtime)
This function handles actual merging of the package contents to the livefs.
source code
 
_merged_path(self, path, lstatobj, exists=True) source code
 
_post_merge_sync(self)
Call this after merge or unmerge, in order to sync relevant files to disk and avoid data-loss in the event of a power failure.
source code
 
merge(self, mergeroot, inforoot, myroot=None, myebuild=None, cleanup=0, mydbapi=None, prev_mtimes=None, counter=None) source code
 
getstring(self, name)
returns contents of a file with whitespace converted to spaces
source code
 
copyfile(self, fname) source code
 
getfile(self, fname) source code
 
setfile(self, fname, data) source code
 
getelements(self, ename) source code
 
setelements(self, mylist, ename) source code
 
isregular(self)
Is this a regular package (does it have a CATEGORY file? A dblink can be virtual *and* regular)
source code
 
_pre_merge_backup(self, backup_dblink, downgrade) source code
 
_pre_unmerge_backup(self, background) source code
 
_quickpkg_dblink(self, backup_dblink, background, logfile) source code

Inherited from object: __delattr__, __format__, __getattribute__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _normalize_needed = re.compile(r'//|^[^/]|./$|(^|/)\.\.?(/|$)')
  _contents_re = re.compile(r'^((?P<dir>(dev|dir|fif) (.+))|(?P<...
  _infodir_cleanup = frozenset([u'dir', u'dir.old'])
  _ignored_unlink_errnos = (16, 2, 20, 21)
  _ignored_rmdir_errnos = (17, 39, 16, 2, 20, 21, 1)
Properties [hide private]

Inherited from object: __class__

Imports: re


Method Details [hide private]

__init__(self, cat, pkg, myroot=None, settings=None, treetype=None, vartree=None, blockers=None, scheduler=None, pipe=None)
(Constructor)

source code 

Creates a DBlink object for a given CPV. The given CPV may not be present in the database already.

Parameters:
  • cat (String) - Category
  • pkg (String) - Package (PV)
  • myroot (String (Path)) - ignored, settings['ROOT'] is used instead
  • settings (portage.config) - Typically portage.settings
  • treetype (String) - one of ['porttree','bintree','vartree']
  • vartree (vartree) - an instance of vartree corresponding to myroot.
Overrides: object.__init__

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(inherited documentation)

unmerge(self, pkgfiles=None, trimworld=None, cleanup=True, ldpath_mtimes=None, others_in_slot=None, needed=None, preserve_paths=None)

source code 

Calls prerm
Unmerges a given package (CPV)
calls postrm
calls cleanrm
calls env_update

@param pkgfiles: files to unmerge (generally self.getcontents() )
@type pkgfiles: Dictionary
@param trimworld: Unused
@type trimworld: Boolean
@param cleanup: cleanup to pass to doebuild (see doebuild)
@type cleanup: Boolean
@param ldpath_mtimes: mtimes to pass to env_update (see env_update)
@type ldpath_mtimes: Dictionary
@param others_in_slot: all dblink instances in this slot, excluding self
@type others_in_slot: list
@param needed: Filename containing libraries needed after unmerge.
@type needed: String
@param preserve_paths: Libraries preserved by a package instance that
        is currently being merged. They need to be explicitly passed to the
        LinkageMap, since they are not registered in the
        PreservedLibsRegistry yet.
@type preserve_paths: set
@rtype: Integer
@return:
1. os.EX_OK if everything went well.
2. return code of the failed phase (for prerm, postrm, cleanrm)

_unmerge_pkgfiles(self, pkgfiles, others_in_slot)

source code 

Unmerges the contents of a package from the liveFS Removes the VDB entry for self

Parameters:
  • pkgfiles (Dictionary { filename: [ 'type', '?', 'md5sum' ] }) - typically self.getcontents()
  • others_in_slot (list) - all dblink instances in this slot, excluding self
Returns: None

isowner(self, filename, destroot=None)

source code 

Check if a file belongs to this package. This may
result in a stat call for the parent directory of
every installed file, since the inode numbers are
used to work around the problem of ambiguous paths
caused by symlinked directories. The results of
stat calls are cached to optimize multiple calls
to this method.

@param filename:
@type filename:
@param destroot:
@type destroot:
@rtype: Boolean
@return:
1. True if this package owns the file.
2. False if this package does not own the file.

_match_contents(self, filename, destroot=None)

source code 

The matching contents entry is returned, which is useful since the path may differ from the one given by the caller, due to symlinks.

Returns: String
the contents entry corresponding to the given path, or False if the file is not owned by this package.

_linkmap_rebuild(self, **kwargs)

source code 

Rebuild the self._linkmap if it's not broken due to missing scanelf binary. Also, return early if preserve-libs is disabled and the preserve-libs registry is empty.

_find_libs_to_preserve(self, unmerge=False)

source code 

Get set of relative paths for libraries to be preserved. When unmerge is False, file paths to preserve are selected from self._installed_instance. Otherwise, paths are selected from self.

_lstat_inode_map(self, path_iter)

source code 

Use lstat to create a map of the form:
  {(st_dev, st_ino) : set([path1, path2, ...])}
Multiple paths may reference the same inode due to hardlinks.
All lstat() calls are relative to self.myroot.

treewalk(self, srcroot, destroot, inforoot, myebuild, cleanup=0, mydbapi=None, prev_mtimes=None, counter=None)

source code 


This function does the following:

calls self._preserve_libs if FEATURES=preserve-libs
calls self._collision_protect if FEATURES=collision-protect
calls doebuild(mydo=pkg_preinst)
Merges the package to the livefs
unmerges old version (if required)
calls doebuild(mydo=pkg_postinst)
calls env_update

@param srcroot: Typically this is ${D}
@type srcroot: String (Path)
@param destroot: ignored, self.settings['ROOT'] is used instead
@type destroot: String (Path)
@param inforoot: root of the vardb entry ?
@type inforoot: String (Path)
@param myebuild: path to the ebuild that we are processing
@type myebuild: String (Path)
@param mydbapi: dbapi which is handed to doebuild.
@type mydbapi: portdbapi instance
@param prev_mtimes: { Filename:mtime } mapping for env_update
@type prev_mtimes: Dictionary
@rtype: Boolean
@return:
1. 0 on success
2. 1 on failure

secondhand is a list of symlinks that have been skipped due to their target
not existing; we will merge these symlinks at a later time.

_new_backup_path(self, p)

source code 

The works for any type path, such as a regular file, symlink, or directory. The parent directory is assumed to exist. The returned filename is of the form p + '.backup.' + x, where x guarantees that the returned path does not exist yet.

mergeme(self, srcroot, destroot, outfile, secondhand, stufftomerge, cfgfiledict, thismtime)

source code 


This function handles actual merging of the package contents to the livefs.
It also handles config protection.

@param srcroot: Where are we copying files from (usually ${D})
@type srcroot: String (Path)
@param destroot: Typically ${ROOT}
@type destroot: String (Path)
@param outfile: File to log operations to
@type outfile: File Object
@param secondhand: A set of items to merge in pass two (usually
or symlinks that point to non-existing files that may get merged later)
@type secondhand: List
@param stufftomerge: Either a diretory to merge, or a list of items.
@type stufftomerge: String or List
@param cfgfiledict: { File:mtime } mapping for config_protected files
@type cfgfiledict: Dictionary
@param thismtime: None or new mtime for merged files (expressed in seconds
in Python <3.3 and nanoseconds in Python >=3.3)
@type thismtime: None or Int
@rtype: None or Boolean
@return:
1. True on failure
2. None otherwise

_post_merge_sync(self)

source code 

Call this after merge or unmerge, in order to sync relevant files to disk and avoid data-loss in the event of a power failure. This method does nothing if FEATURES=merge-sync is disabled.

merge(self, mergeroot, inforoot, myroot=None, myebuild=None, cleanup=0, mydbapi=None, prev_mtimes=None, counter=None)

source code 
Parameters:
  • myroot - ignored, self._eroot is used instead

Class Variable Details [hide private]

_contents_re

Value:
re.compile(r'^((?P<dir>(dev|dir|fif) (.+))|(?P<obj>(obj) (.+) (\S+) (\\
d+))|(?P<sym>(sym) (.+) -> (.+) ((\d+)|(?P<oldsym>(\(\d+, \d+L, \d+L, \
\d+, \d+, \d+, \d+L, \d+, (\d+), \d+\))))))$')