#Tc@s.dZddkZddkZddkZddkZddkZddkZddkZddkZddk Z ddk i i Z ddkiZddkiZddkiZddk lZyddkiZeZWnej o eZnXdeifdYZeieieee_ dS(smodule describing a file packaging object This module contains the FileAction class, which represents a file-type packaging object.iN(tActionExecutionErrort FileActioncBseZdZddgZdZdZdZeZdZ e i eZ eZ eid jod Zd Zd ZndZdZddZdZdZedZdZdZdZddZRS(s0Class representing a file-type packaging object.thashtreplace_requiredtfiletpathtmodetownertgrouptpreservetsysattrtwindowscCs[|pdS|i|ii}tii|o |i|oti|ndS(s*If the file exists, check if it is in use.N( tget_installed_pathtimagetget_roottosRtisfiletin_uset api_errorstFileInUseException(tselftpkgplantorigR((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyt preinstallJs #cCsO|i|ii}tii|o |i|oti|ndS(N( R R RRRRRRR(RRR((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyt preremoveRs#cCsKyti||Wn0tj o$}|itijontSXtS(sfDetermine if a file is in use (locked) by trying to rename the file to itself.(RtrenametOSErrorterrnotEACCEStTruetFalse(RRterr((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyRWscCsd}y"t|iiddd}Wn,ttfj o|id|inX|i||i\}}|i |i i }|i ||t iit ii|p/|it ii|dtid|inH| o?|i o4d|ijo$t ii|o|i|nd|ijo|i|i }n|i||}t}d} |tjp|o|i|ijo t}n|djo.|iidddjo|d} q0nR|djo|d } n7|d jo|d } n|d jo|d }nt ii|ot ii| ot ii|oyt i|Wqtj og} | iti joq| iti!ti"fjo|i|q| iti#joqqXn|oR|i$||o?t%i&dt ii|\} } |i'} t i(| d}zy1t)i*|\}}}ti+| ||}Wngt,i-j oX} t.|dt/ddi0g}| i1D]}|t2|q~d| nXWd|i3| i3X||jo5t.|dt/dh|d6|d6|d6qTn|} yt i4| |Wn3tj o'} | iti joqdSnXyt5i6| ||Wn/tj o#} | iti7joqnX|oQ| oJyt5i8|| Wq?tj o#} | iti joq;q?Xnt5i8| ||od|ijoti9|id}yt i:|||fWq tj oc} | iti#jont i4|t;i<t;i=Bt i:|||ft i4||q Xn|iid}|o|i>d}t?|djo%|dt5i@jo|d}n|}yt5iA||Wqtj o;} | itiBjont.|dt/dqtj o3} t.|dt/dh|d 6| d!6qXndS("s(Client-side method that installs a file.RitfmriR t save_filetlegacys.legacysrenameold.updates.updatet renameolds.oldt renamenews.newtdirtwbtdetailssError decompressing payload: %st terrorNseAction data hash verification failure: expected: %(expected)s computed: %(actual)s action: %(action)stexpectedtactualtactiont timestampR t,iis=System attributes are not supported on the target filesystem.s7Could not set system attributes '%(attrlist)s': %(err)stattrlistR(CtNonetinttattrstgett TypeErrort ValueErrortvalidatetdestination_fmritget_fsobj_uid_gidR R Rtfsobj_checkpathRRtexiststdirnametmakedirstmisct PKG_DIR_MODEt origin_fmriRtsalvaget restore_filet_check_preserveRRtislinktisdirtrmdirRRtENOENTtEEXISTt ENOTEMPTYRt needsdatattempfiletmkstemptdatatfdopentdigesttget_preferred_hashtgunzip_from_streamtzlibR)Rt_tjointargststrtclosetchmodtportabletchowntEPERMRttimestamp_to_timetutimetstattS_IRUSRtS_IWUSRtsplittlentget_sysattr_dicttfsetattrtEINVAL(RRRRRRt final_patht pres_typet do_contenttold_pathtettfilefdttemptstreamttfilet hash_attrthash_valt hash_functshasumt_[1]tatttsattrtsattrstarg((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pytinstallbs"  #           4          c Ks|i|i}|i|ti\}}}}}|o$ti|ip t|_qdn|o%|pt t|_|||fS|i i do"|dtjo|i dnd|i jold|i jo\|iti|i djo<|i tdhti|id6|i dd6nd|i jod |i jottiit|i i oV|it|i d jo9|i td h|id6t|i d d6nd|i jo0|dtjp |d!jo|||fSn|d tjo|||fSy|i id d i dj} d!} d!} ti|dtii\} } }| ot o| oyL| djot}t}n t}t}t!i"|d|d|| } Wn&t#j o}|i d|nX| d!j o/| | jo"tdh| d6| d6} qan| d!jp| o| oti|\}}}ti$|d|\}}||jozd|i jo|i tdq7| o|i | t|_q7|i tdh|d6|d6t|_q;n|i idd!}|o|i%d}t&|djo:|dt'i(jo#t'i)|dt}|d}nt'i)|}x:|D].}||jo|i td|qqWnWnt*j oJ}|i+t+i,jo|i tdq|i td|n-t-j o }|i td |nX|||fS("sReturns a tuple of lists of the form (errors, warnings, info). The error list will be empty if the action has been correctly installed in the given image. In detail, this verifies that the file is present, and if the preserve attribute is not present, that the hashes and other attributes of the file match.s/bobcattverboses<Warning: package may contain bobcat! (http://xkcd.com/325/)R R-s+Timestamp: %(found)s should be %(expected)stfoundR*spkg.sizes,Size: %(found)d bytes should be %(expected)dtforevert mountpointtttruet hash_typespkg.content-hash.sha256tsha1tsha256sELF content hash: %ss2ELF content hash: %(found)s should be %(expected)sRpseditable file has been changeds&Hash: %(found)s should be %(expected)sR R.iitcompactsSystem attribute '%s' not setsSkipping: Permission DeniedsUnexpected Error: %ssUnexpected Exception: %sN(.R Rtverify_fsobj_commonR]tS_IFREGtS_ISREGtst_modeRRtAssertionErrortlowertendswithtappendR2tst_mtimeR=R[RRttime_to_timestamptsetRNtRANKED_CONTENT_HASH_ATTRSt intersectiontkeystst_sizeR1RR0R3ROtpkgt CONTENT_HASHthaveelftelft get_dynamict RuntimeErrortget_data_digestR`RaRXRbtfgetattrtEnvironmentErrorRRt Exception(RtimgRTRtlstatterrorstwarningstinfotaborttis_mtpttelfhashtelferrort ehash_attrt elfhash_valRpt get_sha256tget_sha1RiRnRotsha_hashRLRuRvt set_attrsRs((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pytverifys $ ' !                   cCsy|id}Wntj odSXd|ijodS|i|ii}|djo|ptS|Stii|}t }|ot i ||\}} } } t i |\} } }| o| o| | j}nt}|i og|o`|ioV|i i|iijo=|o1ti|d|\}}|| jodSnt Sn|o|otii|}n|o|o0|p |}nti|d|\}}n| p || jo|d jo|StS| o|| jotSnt S( sReturn the type of preservation needed for this action. Returns None if preservation is not defined by the action. Returns False if it is, but no preservation is necessary. Returns True for the normal preservation form. Returns one of the strings 'renameold', 'renameold.update', 'renamenew', or 'legacy' for each of the respective forms of preservation. R NRR"Rpsrenameold.updateR#R$(s renameolds renamenew(R2tKeyErrorR R RRRRRRRNtget_common_preferred_hashROR7R?tversionR=R(RRRt orig_pathRfRetis_filet changed_hashtcommon_hash_attrtcommon_hash_valtcommon_orig_hash_valtcommon_hash_functhattrt orig_hash_valtorig_hash_functihashtcdatatchash((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyRBsZ            cCs|iotSddkl}|iii|dj}|o$|od|ijo d|ij}|o+ti ||dti \}}}} nti ||\} } } } |p t}n8|o$| djp | djo t}n | | j}|oR| p ||jo=d|ijp$|i p|i i|i ijotSn<|o4|i|ii}tii|ptSn|i||}|djo|tjotStS(Ni(tCONTENT_UPDATE_POLICYs when-requiredRRR (RRtpkg.client.imageconfigRR tcfgtget_policy_strR2RNRRR0R?R7RR RRRRRBR(RRRRtuse_content_hashtbothelftcommon_elf_attrtcommon_elfhashtcommon_orig_elfhashtcommon_elf_funcRRRRRRRf((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyRI?s@           c Cs|i|ii}|iid}|o3|d}|i|i||djodSnyti|ti ti BWn0t j o$}|i t i jodSnX|i o|iiddidjoyVti|\}}}ti|d|\} } | |jo|i|dSWqotj o$}|i t i jodSqoXn|i||dS(NR!iR~R tfalseRp(R R RR2R3R!RRWR]tS_IWRITEtS_IREADRRRFR7RRNROR=RR@Rt remove_fsobj( RRRR!tremoveRiRnRoRpRR((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyR~s6    "     cCsCd|ijod|ijo t}ntii||d|S(NRtcmp_hash(R2RtgenerictActiont different(RtotherR((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pyRs  cCsdd|i|ifdd|idfddtii|iddfddtii|iddfg}xKtiD]@}|djoqyn|i|}|i d||dfqyW|S(swGenerates the indices needed by the search dictionary. See generic.py for a more detailed explanation.RtcontentRtbasenameRN( RR0RRRR2tsepRNtDEFAULT_HASH_ATTRSR(Rt index_listtattrR((s6/usr/lib/python2.6/vendor-packages/pkg/actions/file.pytgenerate_indicess &   cCs|i}yti||Wn5tj o)}|itijond}nX|i}||f|i|i dds.