<s> import ctypes <EOL> import inspect , itertools , re , rpm , os , pwd , stat , tempfile <EOL> from ctypes import c_void_p , c_long , c_int <EOL> from conary import files , trove <EOL> from conary import rpmhelper <EOL> from conary import versions <EOL> from conary . conaryclient import filetypes <EOL> from conary . deps import deps <EOL> from conary . lib import elf , util , log <EOL> from conary . lib import sha1helper <EOL> from conary . lib . compat import namedtuple <EOL> from conary . local import capsules <EOL> from conary . local . capsules import SingleCapsuleOperation <EOL> from conary . local import errors <EOL> from conary . repository import changeset <EOL> from conary . repository import filecontents <EOL> try : <EOL> BaseCapsulePlugin = capsules . BaseCapsulePlugin <EOL> except AttributeError : <EOL> BaseCapsulePlugin = object <EOL> def rpmkey ( hdr ) : <EOL> return "<STR_LIT>" % ( hdr [ '<STR_LIT:name>' ] , hdr [ '<STR_LIT:version>' ] , <EOL> hdr [ '<STR_LIT>' ] , hdr [ '<STR_LIT>' ] ) <EOL> class Callback : <EOL> def __init__ ( self , callback , totalSize , logFd ) : <EOL> self . fdnos = { } <EOL> self . callback = callback <EOL> self . totalSize = totalSize <EOL> self . logFd = logFd <EOL> self . lastAmount = <NUM_LIT:0> <EOL> self . rootFd = os . open ( "<STR_LIT:/>" , os . O_RDONLY ) <EOL> self . unpackFailures = [ ] <EOL> def flushRpmLog ( self ) : <EOL> s = os . read ( self . logFd , <NUM_LIT> ) <EOL> data = '<STR_LIT>' <EOL> while s : <EOL> data += s <EOL> s = os . read ( self . logFd , <NUM_LIT> ) <EOL> lines = data . split ( '<STR_LIT:\n>' ) <EOL> if not lines : <EOL> return <EOL> thisRoot = os . open ( "<STR_LIT:/>" , os . O_RDONLY ) <EOL> thisDir = os . open ( "<STR_LIT:.>" , os . O_RDONLY ) <EOL> concats = [ ] <EOL> try : <EOL> os . fchdir ( self . rootFd ) <EOL> os . chroot ( "<STR_LIT:.>" ) <EOL> for line in lines : <EOL> line . strip ( ) <EOL> if not line : <EOL> continue <EOL> if '<STR_LIT>' in line : <EOL> concats . append ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> elif '<STR_LIT>' in line : <EOL> concats . append ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> line = line [ <NUM_LIT:6> : ] . strip ( ) <EOL> self . callback . error ( line ) <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> line = line [ <NUM_LIT:8> : ] . strip ( ) <EOL> self . callback . warning ( line ) <EOL> else : <EOL> self . callback . warning ( line ) <EOL> finally : <EOL> os . fchdir ( thisRoot ) <EOL> os . close ( thisRoot ) <EOL> os . chroot ( "<STR_LIT:.>" ) <EOL> os . fchdir ( thisDir ) <EOL> os . close ( thisDir ) <EOL> for ( keepPath , fromPath ) in concats : <EOL> finalLines = open ( fromPath ) . readlines ( ) + open ( keepPath ) . readlines ( ) <EOL> finalLines = [ ( x . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] , x ) for x in finalLines ] <EOL> seen = set ( ) <EOL> f = open ( keepPath , "<STR_LIT:w>" ) <EOL> for ( name , line ) in finalLines : <EOL> if name not in seen : <EOL> seen . add ( name ) <EOL> f . write ( line ) <EOL> f . close ( ) <EOL> os . unlink ( fromPath ) <EOL> def __call__ ( self , what , amount , total , mydata , wibble ) : <EOL> self . flushRpmLog ( ) <EOL> if what == rpm . RPMCALLBACK_TRANS_START : <EOL> pass <EOL> elif what == rpm . RPMCALLBACK_INST_OPEN_FILE : <EOL> hdr , path = mydata <EOL> fd = os . open ( path , os . O_RDONLY | os . O_NONBLOCK ) <EOL> self . fdnos [ rpmkey ( hdr ) ] = fd <EOL> self . lastAmount = <NUM_LIT:0> <EOL> return fd <EOL> elif what == rpm . RPMCALLBACK_INST_CLOSE_FILE : <EOL> hdr , path = mydata <EOL> os . close ( self . fdnos [ rpmkey ( hdr ) ] ) <EOL> del self . fdnos [ rpmkey ( hdr ) ] <EOL> elif what == rpm . RPMCALLBACK_INST_PROGRESS : <EOL> self . callback . restoreFiles ( amount - self . lastAmount , <EOL> self . totalSize ) <EOL> self . lastAmount = amount <EOL> elif what == rpm . RPMCALLBACK_UNPACK_ERROR : <EOL> hdr , path = mydata <EOL> self . unpackFailures . append ( hdr ) <EOL> def __del__ ( self ) : <EOL> assert ( not self . fdnos ) <EOL> self . flushRpmLog ( ) <EOL> os . close ( self . rootFd ) <EOL> class RpmCapsuleOperation ( SingleCapsuleOperation ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> SingleCapsuleOperation . __init__ ( self , * args , ** kwargs ) <EOL> self . netSharedPath = set ( ) <EOL> nsp = rpmExpandMacro ( '<STR_LIT>' ) <EOL> if nsp != '<STR_LIT>' : <EOL> self . netSharedPath = set ( nsp . split ( '<STR_LIT::>' ) ) <EOL> @ staticmethod <EOL> def _canonicalNvra ( n , v , r , a ) : <EOL> return "<STR_LIT>" % ( n , v , r , a ) <EOL> def _CheckRPMDBContents ( self , testNvras , ts , errStr , <EOL> unpackFailures = None , enforceUnpackFailures = None ) : <EOL> mi = ts . dbMatch ( ) <EOL> installedNvras = set ( [ ( h [ '<STR_LIT:name>' ] , h [ '<STR_LIT:version>' ] , h [ '<STR_LIT>' ] , h [ '<STR_LIT>' ] ) <EOL> for h in mi ] ) <EOL> missingNvras = testNvras . difference ( installedNvras ) <EOL> if unpackFailures and not enforceUnpackFailures : <EOL> missingNvras -= unpackFailures <EOL> self . callback . warning ( '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( <EOL> self . _canonicalNvra ( * nvra ) for nvra in unpackFailures ) ) <EOL> if missingNvras : <EOL> missingSpecs = sorted ( [ self . _canonicalNvra ( * nvra ) <EOL> for nvra in missingNvras ] ) <EOL> raise errors . UpdateError ( errStr + '<STR_LIT:U+0020>' . join ( missingSpecs ) ) <EOL> def doApply ( self , fileDict , justDatabase = False , noScripts = False ) : <EOL> pwd . getpwall ( ) <EOL> util . mkdirChain ( os . path . join ( self . root , '<STR_LIT>' ) ) <EOL> ts = rpm . TransactionSet ( self . root , rpm . _RPMVSF_NOSIGNATURES ) <EOL> installNvras = set ( ) <EOL> removeNvras = set ( [ ( trv . troveInfo . capsule . rpm . name ( ) , <EOL> trv . troveInfo . capsule . rpm . version ( ) , <EOL> trv . troveInfo . capsule . rpm . release ( ) , <EOL> trv . troveInfo . capsule . rpm . arch ( ) ) <EOL> for trv in self . removes ] ) <EOL> self . _CheckRPMDBContents ( removeNvras , ts , <EOL> '<STR_LIT>' ) <EOL> tsFlags = <NUM_LIT:0> <EOL> if justDatabase : <EOL> tsFlags |= rpm . RPMTRANS_FLAG_JUSTDB <EOL> if noScripts : <EOL> tsFlags |= rpm . RPMTRANS_FLAG_NOSCRIPTS <EOL> ts . setFlags ( tsFlags ) <EOL> ts . setProbFilter ( rpm . RPMPROB_FILTER_IGNOREOS | <EOL> rpm . RPMPROB_FILTER_IGNOREARCH | <EOL> rpm . RPMPROB_FILTER_REPLACEPKG | <EOL> rpm . RPMPROB_FILTER_REPLACENEWFILES | <EOL> rpm . RPMPROB_FILTER_REPLACEOLDFILES | <EOL> rpm . RPMPROB_FILTER_OLDPACKAGE ) <EOL> for troveCs , ( pathId , path , fileId , sha1 ) in self . installs : <EOL> localPath = fileDict [ ( pathId , fileId ) ] <EOL> fd = os . open ( localPath , os . O_RDONLY ) <EOL> hdr = ts . hdrFromFdno ( fd ) <EOL> installNvras . add ( <EOL> ( hdr [ '<STR_LIT:name>' ] , hdr [ '<STR_LIT:version>' ] , hdr [ '<STR_LIT>' ] , hdr [ '<STR_LIT>' ] ) ) <EOL> os . close ( fd ) <EOL> ts . addInstall ( hdr , ( hdr , localPath ) , "<STR_LIT:i>" ) <EOL> hasTransaction = True <EOL> if ( rpm . __dict__ . has_key ( '<STR_LIT>' ) and <EOL> rpm . RPMTAG_LONGARCHIVESIZE in hdr . keys ( ) ) : <EOL> thisSize = hdr [ rpm . RPMTAG_LONGARCHIVESIZE ] <EOL> else : <EOL> thisSize = hdr [ rpm . RPMTAG_ARCHIVESIZE ] <EOL> self . fsJob . addToRestoreSize ( thisSize ) <EOL> removeNvras -= installNvras <EOL> afterInstall = set ( self . db . findByNames ( <EOL> [ x . getName ( ) for x in self . removes ] ) ) <EOL> afterInstall -= set ( x [ <NUM_LIT:0> ] . getNewNameVersionFlavor ( ) <EOL> for x in self . installs ) <EOL> neededNvras = set ( ( trv . troveInfo . capsule . rpm . name ( ) , <EOL> trv . troveInfo . capsule . rpm . version ( ) , <EOL> trv . troveInfo . capsule . rpm . release ( ) , <EOL> trv . troveInfo . capsule . rpm . arch ( ) ) <EOL> for trv in self . db . iterTroves ( afterInstall ) <EOL> if trv . troveInfo . capsule . type ( ) == trove . _TROVECAPSULE_TYPE_RPM ) <EOL> removeNvras -= neededNvras <EOL> for nvra in removeNvras : <EOL> ts . addErase ( "<STR_LIT>" % nvra ) <EOL> ts . check ( ) <EOL> ts . order ( ) <EOL> orderedKeys = [ ] <EOL> transactionKeys = ts . getKeys ( ) <EOL> if transactionKeys is not None : <EOL> for te in transactionKeys : <EOL> if te is not None : <EOL> h = te [ <NUM_LIT:0> ] <EOL> orderedKeys . append ( "<STR_LIT>" % ( <EOL> h [ '<STR_LIT:name>' ] , h [ '<STR_LIT:version>' ] , h [ '<STR_LIT>' ] , h [ '<STR_LIT>' ] ) ) <EOL> if orderedKeys : <EOL> log . syslog ( '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( orderedKeys ) ) <EOL> tmpfd , tmpPath = tempfile . mkstemp ( ) <EOL> writeFile = os . fdopen ( tmpfd , "<STR_LIT>" ) <EOL> readFile = os . open ( tmpPath , os . O_RDONLY ) <EOL> rpm . setLogFile ( writeFile ) <EOL> cb = Callback ( self . callback , self . fsJob . getRestoreSize ( ) , readFile ) <EOL> probs = ts . run ( cb , '<STR_LIT>' ) <EOL> unpackFailures = set ( ( h [ '<STR_LIT:name>' ] , h [ '<STR_LIT:version>' ] , h [ '<STR_LIT>' ] , h [ '<STR_LIT>' ] ) <EOL> for h in cb . unpackFailures ) <EOL> del cb <EOL> writeFile . close ( ) <EOL> os . close ( readFile ) <EOL> if probs : <EOL> raise ValueError ( str ( probs ) ) <EOL> self . _CheckRPMDBContents ( installNvras , ts , <EOL> '<STR_LIT>' , <EOL> unpackFailures = unpackFailures , <EOL> enforceUnpackFailures = False ) <EOL> def install ( self , flags , troveCs ) : <EOL> ACTION_RESTORE = <NUM_LIT:1> <EOL> ACTION_SKIP = <NUM_LIT:2> <EOL> ACTION_CONFLICT = <NUM_LIT:3> <EOL> rc = SingleCapsuleOperation . install ( self , flags , troveCs ) <EOL> if rc is None : <EOL> return None <EOL> ( oldTrv , trv ) = rc <EOL> trvInfo = troveCs . getNewNameVersionFlavor ( ) <EOL> oldTrvInfo = troveCs . getOldNameVersionFlavor ( ) <EOL> hasCapsule = troveCs . hasCapsule ( ) <EOL> toRestore = [ ] <EOL> changedByPathId = dict ( ( x [ <NUM_LIT:0> ] , x ) for x in troveCs . getChangedFileList ( ) ) <EOL> unchangedByPathId = ( set ( x [ <NUM_LIT:0> ] for x in trv . iterFileList ( ) ) - <EOL> set ( changedByPathId . iterkeys ( ) ) - <EOL> set ( x [ <NUM_LIT:0> ] for x in troveCs . getNewFileList ( ) ) - <EOL> set ( troveCs . getOldFileList ( ) ) ) <EOL> l = [ ] <EOL> for oldFileInfo in troveCs . getChangedFileList ( ) : <EOL> oldFileId , oldVersion = oldTrv . getFile ( oldFileInfo [ <NUM_LIT:0> ] ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> l . append ( ( oldFileInfo [ <NUM_LIT:0> ] , oldFileId , oldVersion ) ) <EOL> for unchangedPathId in unchangedByPathId : <EOL> unchangedFileId , unchangedFileVersion = trv . getFile ( unchangedPathId ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> l . append ( ( unchangedPathId , unchangedFileId , unchangedFileVersion ) ) <EOL> fileObjs = self . db . getFileVersions ( l ) <EOL> fileObjsByPathId = dict ( <EOL> [ ( x [ <NUM_LIT:0> ] , y ) for x , y in <EOL> itertools . izip ( l , fileObjs ) ] ) <EOL> for fileInfo in trv . iterFileList ( ) : <EOL> pathId , path , fileId , version = fileInfo <EOL> if os . path . dirname ( path ) in self . netSharedPath : <EOL> continue <EOL> if pathId in changedByPathId : <EOL> oldFileId = oldTrv . getFile ( pathId ) [ <NUM_LIT:1> ] <EOL> fileChange = self . changeSet . getFileChange ( oldFileId , fileId ) <EOL> if ( oldFileId == fileId ) : <EOL> fileObj = fileObjsByPathId [ pathId ] <EOL> elif fileChange [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> fileObj = fileObjsByPathId [ pathId ] <EOL> fileObj . twm ( fileChange , fileObj ) <EOL> else : <EOL> fileObj = files . ThawFile ( fileChange , pathId ) <EOL> elif pathId in unchangedByPathId : <EOL> fileObj = fileObjsByPathId [ pathId ] <EOL> else : <EOL> fileStream = self . changeSet . getFileChange ( None , fileId ) <EOL> fileObj = files . ThawFile ( fileStream , pathId ) <EOL> absolutePath = util . joinPaths ( self . root , path ) <EOL> if ( fileObj . flags . isCapsuleAddition ( ) ) : <EOL> continue <EOL> elif ( trove . conaryContents ( hasCapsule , pathId , fileObj ) <EOL> and fileObj . lsTag != '<STR_LIT:d>' ) : <EOL> self . preservePath ( path , unlink = True ) <EOL> continue <EOL> s = util . lstat ( absolutePath ) <EOL> if not s : <EOL> toRestore . append ( ( fileInfo , fileObj ) ) <EOL> continue <EOL> action = ACTION_CONFLICT <EOL> existingOwners = list ( <EOL> self . db . iterFindPathReferences ( path , justPresent = True , <EOL> withStream = True ) ) <EOL> if existingOwners : <EOL> l = [ x for x in existingOwners if x [ <NUM_LIT:0> : <NUM_LIT:3> ] == oldTrvInfo ] <EOL> if l : <EOL> existingOwners . remove ( l [ <NUM_LIT:0> ] ) <EOL> if not existingOwners : <EOL> action = ACTION_RESTORE <EOL> elif stat . S_ISDIR ( s . st_mode ) and fileObj . lsTag == '<STR_LIT:d>' : <EOL> action = ACTION_RESTORE <EOL> elif fileObj . flags . isInitialContents ( ) : <EOL> action = ACTION_RESTORE <EOL> if action == ACTION_CONFLICT and not existingOwners : <EOL> if self . fsJob . findAliasedRemovals ( absolutePath ) : <EOL> action = ACTION_RESTORE <EOL> if action == ACTION_CONFLICT and existingOwners : <EOL> if fileId in [ x [ <NUM_LIT:4> ] for x in existingOwners ] : <EOL> for info in existingOwners : <EOL> self . fsJob . sharedFile ( info [ <NUM_LIT:0> ] , info [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] , <EOL> info [ <NUM_LIT:3> ] ) <EOL> action = ACTION_RESTORE <EOL> elif path . startswith ( '<STR_LIT>' ) : <EOL> action = ACTION_RESTORE <EOL> else : <EOL> existingFiles = [ files . ThawFile ( x [ <NUM_LIT:5> ] , pathId ) for x <EOL> in existingOwners ] <EOL> compatibility = [ <NUM_LIT:1> for x in existingFiles <EOL> if fileObj . compatibleWith ( x ) ] <EOL> if <NUM_LIT:1> in compatibility : <EOL> for info in existingOwners : <EOL> self . fsJob . sharedFile ( info [ <NUM_LIT:0> ] , info [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] , <EOL> info [ <NUM_LIT:3> ] ) <EOL> action = ACTION_RESTORE <EOL> elif <NUM_LIT:1> in [ files . rpmFileColorCmp ( x , fileObj ) <EOL> for x in existingFiles ] : <EOL> action = ACTION_SKIP <EOL> elif ( self . _checkReplaceManagedFiles ( flags , path ) or <EOL> <NUM_LIT:1> in [ files . rpmFileColorCmp ( fileObj , x ) <EOL> for x in existingFiles ] ) : <EOL> existingFile = files . FileFromFilesystem ( absolutePath , <EOL> pathId ) <EOL> for info in existingOwners : <EOL> self . fsJob . userRemoval ( <EOL> fileObj = existingFile , <EOL> content = <EOL> filecontents . FromFilesystem ( absolutePath ) , <EOL> * info [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> action = ACTION_RESTORE <EOL> else : <EOL> action = ACTION_RESTORE <EOL> elif flags . replaceUnmanagedFiles : <EOL> action = ACTION_RESTORE <EOL> if action == ACTION_RESTORE : <EOL> toRestore . append ( ( fileInfo , fileObj ) ) <EOL> elif action == ACTION_CONFLICT : <EOL> self . _error ( errors . FileInWayError ( util . normpath ( path ) , <EOL> troveCs . getName ( ) , <EOL> troveCs . getNewVersion ( ) , <EOL> troveCs . getNewFlavor ( ) ) ) <EOL> else : <EOL> assert ( action == ACTION_SKIP ) <EOL> self . preservePath ( path , unlink = False ) <EOL> self . fsJob . userRemoval ( trv . getName ( ) , trv . getVersion ( ) , <EOL> trv . getFlavor ( ) , pathId ) <EOL> for fileInfo , fileObj in toRestore : <EOL> fullPath = util . joinPaths ( self . root , path ) <EOL> self . fsJob . _restore ( fileObj , fullPath , trvInfo , <EOL> "<STR_LIT>" , <EOL> restoreFile = False , <EOL> fileId = fileId ) <EOL> @ classmethod <EOL> def _checkReplaceManagedFiles ( cls , flags , path ) : <EOL> if inspect . ismethod ( flags . replaceManagedFiles ) : <EOL> return flags . replaceManagedFiles ( path ) <EOL> return bool ( flags . replaceManagedFiles ) <EOL> def remove ( self , trv ) : <EOL> SingleCapsuleOperation . remove ( self , trv ) <EOL> for trv in self . removes : <EOL> dbFileObjs = self . db . getFileVersions ( <EOL> [ ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:2> ] , x [ <NUM_LIT:3> ] ) for x in trv . iterFileList ( ) ] ) <EOL> for ( pathId , path , fileId , version ) , fileObj in itertools . izip ( trv . iterFileList ( ) , dbFileObjs ) : <EOL> hasCapsule = trv . troveInfo . capsule . type ( ) or False <EOL> fullPath = util . joinPaths ( self . root , path ) <EOL> if not os . path . exists ( fullPath ) : <EOL> continue <EOL> if ( fileObj . flags . isCapsuleAddition ( ) ) : <EOL> continue <EOL> elif ( fileObj . hasContents and <EOL> trove . conaryContents ( hasCapsule , pathId , fileObj ) ) : <EOL> self . preservePath ( path , unlink = True ) <EOL> continue <EOL> fsFileObj = files . FileFromFilesystem ( fullPath , pathId , <EOL> possibleMatch = fileObj ) <EOL> self . fsJob . _remove ( fsFileObj , path , fullPath , <EOL> '<STR_LIT>' , <EOL> ignoreMissing = True ) <EOL> class RpmCapsulePlugin ( BaseCapsulePlugin ) : <EOL> kind = '<STR_LIT>' <EOL> @ staticmethod <EOL> def _digest ( rpmlibHeader ) : <EOL> if rpmhelper . SIG_SHA1 in rpmlibHeader . keys ( ) : <EOL> return sha1helper . sha1FromString ( <EOL> rpmlibHeader [ rpmhelper . SIG_SHA1 ] ) <EOL> else : <EOL> return None <EOL> @ staticmethod <EOL> def _getCapsuleKeyFromInfo ( capsuleStream ) : <EOL> nevra = capsuleStream . rpm . getNevra ( ) <EOL> digest = capsuleStream . rpm . sha1header ( ) <EOL> return capsules . PartialTuple ( ( nevra , digest ) ) <EOL> def getCapsuleKeysFromTarget ( self ) : <EOL> txnSet = rpm . TransactionSet ( self . root ) <EOL> matchIter = txnSet . dbMatch ( ) <EOL> headersByKey = { } <EOL> for rpmlibHeader in matchIter : <EOL> nevra = rpmhelper . NEVRA . fromHeader ( rpmlibHeader ) <EOL> if nevra . name . startswith ( '<STR_LIT>' ) and not nevra . arch : <EOL> continue <EOL> digest = self . _digest ( rpmlibHeader ) <EOL> key = capsules . PartialTuple ( ( nevra , digest ) ) <EOL> headersByKey [ key ] = rpmlibHeader <EOL> return headersByKey <EOL> def _getPhantomNVF ( self , header ) : <EOL> """<STR_LIT>""" <EOL> binCount = <NUM_LIT:1> <EOL> while True : <EOL> name , _ , version , release , arch = header . getNevra ( ) <EOL> name += '<STR_LIT>' <EOL> verstr = '<STR_LIT>' % ( version , release ) <EOL> if arch != '<STR_LIT>' : <EOL> verstr += '<STR_LIT:_>' + arch <EOL> verstr += '<STR_LIT>' % binCount <EOL> revision = versions . Revision ( verstr ) <EOL> revision . resetTimeStamp ( ) <EOL> version = versions . Version ( [ versions . PhantomLabel ( ) , revision ] ) <EOL> flavor = deps . Flavor ( ) <EOL> if not self . db . hasTrove ( name , version , flavor ) : <EOL> return name , version , flavor <EOL> binCount += <NUM_LIT:1> <EOL> def _addPhantomContents ( self , changeSet , trv , header ) : <EOL> """<STR_LIT>""" <EOL> for ( path , owner , group , mode , size , rdev , flags , vflags , linkto , <EOL> mtime ) in itertools . izip ( <EOL> header [ rpmhelper . OLDFILENAMES ] , <EOL> header [ rpmhelper . FILEUSERNAME ] , <EOL> header [ rpmhelper . FILEGROUPNAME ] , <EOL> header [ rpmhelper . FILEMODES ] , <EOL> header [ rpmhelper . FILESIZES ] , <EOL> header [ rpmhelper . FILERDEVS ] , <EOL> header [ rpmhelper . FILEFLAGS ] , <EOL> header [ rpmhelper . FILEVERIFYFLAGS ] , <EOL> header [ rpmhelper . FILELINKTOS ] , <EOL> header [ rpmhelper . FILEMTIMES ] , <EOL> ) : <EOL> fullPath = util . joinPaths ( self . root , path ) <EOL> fakestat = FakeStat ( mode , <NUM_LIT:0> , None , <NUM_LIT:1> , owner , group , size , <EOL> mtime , mtime , mtime , st_rdev = rdev , linkto = linkto ) <EOL> pathId = os . urandom ( <NUM_LIT:16> ) <EOL> kind = '<STR_LIT>' <EOL> if flags & rpmhelper . RPMFILE_GHOST : <EOL> kind = '<STR_LIT>' <EOL> elif flags & ( rpmhelper . RPMFILE_CONFIG <EOL> | rpmhelper . RPMFILE_MISSINGOK <EOL> | rpmhelper . RPMFILE_NOREPLACE ) : <EOL> if size : <EOL> kind = '<STR_LIT>' <EOL> else : <EOL> kind = '<STR_LIT>' <EOL> elif vflags : <EOL> if ( stat . S_ISREG ( mode ) <EOL> and not ( vflags & rpmhelper . RPMVERIFY_FILEDIGEST ) <EOL> or ( stat . S_ISLNK ( mode ) <EOL> and not ( vflags & rpmhelper . RPMVERIFY_LINKTO ) ) ) : <EOL> kind = '<STR_LIT>' <EOL> fileStream = files . FileFromFilesystem ( fullPath , pathId , <EOL> statBuf = fakestat , sha1FailOk = True ) <EOL> if kind == '<STR_LIT>' : <EOL> fileStream . flags . isConfig ( set = True ) <EOL> elif kind == '<STR_LIT>' : <EOL> fileStream . flags . isInitialContents ( set = True ) <EOL> else : <EOL> assert kind == '<STR_LIT>' <EOL> if ( isinstance ( fileStream , files . RegularFile ) <EOL> and not fileStream . flags . isConfig ( ) <EOL> and not ( fileStream . flags . isInitialContents ( ) <EOL> and not fileStream . contents . size ( ) ) ) : <EOL> fileStream . flags . isEncapsulatedContent ( set = True ) <EOL> fileId = fileStream . fileId ( ) <EOL> trv . addFile ( pathId , path , trv . getVersion ( ) , fileId ) <EOL> changeSet . addFile ( None , fileId , fileStream . freeze ( ) ) <EOL> if ( fileStream . hasContents <EOL> and not fileStream . flags . isEncapsulatedContent ( ) ) : <EOL> if fileStream . contents . sha1 ( ) == sha1helper . sha1Empty : <EOL> contents = filecontents . FromString ( '<STR_LIT>' ) <EOL> else : <EOL> contents = filecontents . FromFilesystem ( fullPath ) <EOL> changeSet . addFileContents ( pathId , fileId , <EOL> contType = changeset . ChangedFileTypes . file , <EOL> contents = contents , <EOL> cfgFile = fileStream . flags . isConfig ( ) , <EOL> ) <EOL> def _addPhantomTrove ( self , changeSet , rpmlibHeader , callback , num , total ) : <EOL> header = rpmhelper . headerFromBlob ( rpmlibHeader . unload ( ) ) <EOL> callback . capsuleSyncCreate ( self . kind , str ( header . getNevra ( ) ) , num , <EOL> total ) <EOL> name , version , flavor = self . _getPhantomNVF ( header ) <EOL> trv = trove . Trove ( name , version , flavor ) <EOL> provides = header . getProvides ( ) <EOL> provides . addDep ( deps . TroveDependencies , deps . Dependency ( name ) ) <EOL> trv . setProvides ( provides ) <EOL> trv . setRequires ( header . getRequires ( enableRPMVersionDeps = False ) ) <EOL> path = str ( header . getNevra ( ) ) + '<STR_LIT>' <EOL> fileHelper = filetypes . RegularFile ( contents = '<STR_LIT>' ) <EOL> fileStream = fileHelper . get ( pathId = trove . CAPSULE_PATHID ) <EOL> trv . addRpmCapsule ( path , version , fileStream . fileId ( ) , header ) <EOL> changeSet . addFile ( None , fileStream . fileId ( ) , fileStream . freeze ( ) ) <EOL> self . _addPhantomContents ( changeSet , trv , header ) <EOL> trv . computeDigests ( ) <EOL> changeSet . newTrove ( trv . diff ( None ) [ <NUM_LIT:0> ] ) <EOL> pkgName = name . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> if self . db . hasTrove ( pkgName , version , flavor ) : <EOL> return <EOL> pkg = trove . Trove ( pkgName , version , flavor ) <EOL> provides = deps . DependencySet ( ) <EOL> provides . addDep ( deps . TroveDependencies , deps . Dependency ( pkgName ) ) <EOL> pkg . setProvides ( provides ) <EOL> pkg . setIsCollection ( True ) <EOL> pkg . addTrove ( name , version , flavor , byDefault = True ) <EOL> pkg . computeDigests ( ) <EOL> changeSet . newTrove ( pkg . diff ( None ) [ <NUM_LIT:0> ] ) <EOL> def rpmExpandMacro ( val ) : <EOL> if getattr ( rpm , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> rawRpmModulePath = rpm . _rpm . __file__ <EOL> else : <EOL> rawRpmModulePath = rpm . __file__ <EOL> sonames = [ x [ <NUM_LIT:1> ] for x in elf . inspect ( rawRpmModulePath ) [ <NUM_LIT:0> ] <EOL> if x [ <NUM_LIT:0> ] == '<STR_LIT>' ] <EOL> rpmLibs = [ x for x in sonames if re . match ( '<STR_LIT>' , x ) ] <EOL> assert ( len ( rpmLibs ) == <NUM_LIT:1> ) <EOL> librpm = ctypes . CDLL ( rpmLibs [ <NUM_LIT:0> ] ) <EOL> librpm . expandMacros . argtypes = ( c_void_p , c_void_p , c_void_p , c_long ) <EOL> librpm . expandMacros . restype = c_int <EOL> buf = ctypes . create_string_buffer ( val , len ( val ) * <NUM_LIT:100> ) <EOL> rc = librpm . expandMacros ( None , None , buf , len ( buf ) ) <EOL> if rc != <NUM_LIT:0> : <EOL> raise RuntimeError ( "<STR_LIT>" % ( val , ) ) <EOL> return buf . value <EOL> class FakeStat ( namedtuple ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) : <EOL> __slots__ = ( ) <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> out = [ None ] * len ( cls . _fields ) <EOL> names = set ( cls . _fields ) <EOL> for n , arg in enumerate ( args ) : <EOL> out [ n ] = arg <EOL> names . remove ( cls . _fields [ n ] ) <EOL> for key , arg in kwargs . items ( ) : <EOL> out [ cls . _fields . index ( key ) ] = arg <EOL> names . remove ( key ) <EOL> return tuple . __new__ ( cls , out ) </s>
