ó #ßøTc@s,dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl j j Z ddljZddljZddljZddl mZyddljZeZWnek róeZnXdejfd„ƒYZejejeeƒe_ dS(s„module describing a file packaging object This module contains the FileAction class, which represents a file-type packaging object.iÿÿÿÿN(tActionExecutionErrort FileActioncBsÛeZdZddgZdZdZdZeZdZ e j eZ eZ ejd krvd „Zd „Zd „Znd„Zd„Zdd„Zd„Zd„Zed„Zd„Zd„Zd„Zdd„ZRS(s0Class representing a file-type packaging object.thashtreplace_requiredtfiletpathtmodetownertgrouptpreservetsysattrtwindowscCsV|s dS|j|jjƒƒ}tjj|ƒrR|j|ƒrRtj|‚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.7/vendor-packages/pkg/actions/file.pyt preinstallJs !cCsL|j|jjƒƒ}tjj|ƒrH|j|ƒrHtj|‚ndS(N( R R RRRRRRR(RRR((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pyt preremoveRs!cCsGytj||ƒWn,tk rB}|jtjkr>‚ntSXtS(sfDetermine if a file is in use (locked) by trying to rename the file to itself.(RtrenametOSErrorterrnotEACCEStTruetFalse(RRterr((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pyRWsc CsÁd}y"t|jjddƒdƒ}Wn*ttfk rT|jd|jƒnX|j||jƒ\}}|j |j j ƒƒ}|j ||ƒt jjt jj|ƒƒsä|jt jj|ƒdtjd|jƒnB| r&|j r&d|jkr&t jj|ƒr&|j|ƒnd|jkrJ|j|j ƒ}n|j||ƒ}t}d} |tksŒ|r•|j|jkr•t}n‚|dkrÌ|jjddƒdkr|d} qnK|dkrå|d } n2|d krþ|d } n|d kr|d }nt jj|ƒrÐt jj|ƒ rÐt jj|ƒrÐyt j|ƒWqÐtk rÌ} | jtj kr†qÍ| jtj!tj"fkr±|j|ƒqÍ| jtj#krÍ‚qÍqÐXn|r|j$||ƒrt%j&dt jj|ƒƒ\} } |j'ƒ} t j(| dƒ}z•y1t)j*|ƒ\}}}tj+| ||ƒ}Wn]t,j-k r½} t.|dt/dƒdj0g| j1D]}t2|ƒ^q•ƒd| ƒ‚nXWd|j3ƒ| j3ƒX||kr t.|dt/dƒi|d6|d6|d6ƒ‚q n|} yt j4| |ƒWn/tk re} | jtj kr^‚qfdSnXyt5j6| ||ƒWn+tk rª} | jtj7kr«‚q«nX|rü| rüyt5j8|| ƒWqütk rø} | jtj krù‚qùqüXnt5j8| |ƒ|rÂd|jkrÂtj9|jdƒ}yt j:|||fƒWqÂtk r¾} | jtj#kr{‚nt j4|t;j<t;j=Bƒt j:|||fƒt j4||ƒqÂXn|jjdƒ}|r½|j>dƒ}t?|ƒdkr|dt5j@ƒkr|d}n|}yt5jA||ƒWq½tk r}} | jtjBkrb‚nt.|dt/dƒƒ‚q½tk r¹} t.|dt/dƒi|d 6| d!6ƒ‚q½XndS("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_functshasumtatttsattrtsattrstarg((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pytinstallbsì"   !               ,            cKsT|j|jƒƒ}|j|tjƒ\}}}}}|r`tj|jƒs`t|_q`n|rˆ|srt ‚t|_|||fS|j ƒj dƒr½|dtkr½|j dƒnd|j kr5d|j kr5|jtj|j dƒkr5|j tdƒitj|jƒd6|j dd6ƒnd|j krÏd |j krÏttjƒjt|j jƒƒƒ rÏ|jt|j d ƒkrÏ|j td ƒi|jd6t|j d ƒd6ƒnd|j kr |dtksú|d!kr |||fSn|d tkr'|||fSy¢|j jd d ƒj ƒdk} d!} d!} tj|dtjjƒ\} } }| r;t r;| r;yJ| dkr¬t}t}n t}t}t!j"|d|d|ƒ| } Wn$t#k rþ}|j d|ƒnX| d!k r;| | kr;tdƒi| d6| d6} q;n| d!ksM| r | r tj|ƒ\}}}tj$|d|ƒ\}}||kr d|j kr¸|j tdƒƒq| r×|j | ƒt|_q|j tdƒi|d6|d6ƒt|_q n|j jdd!ƒ}|rÈ|j%dƒ}t&|ƒdkr|dt'j(ƒkrt'j)|dtƒ}|d}nt'j)|ƒ}x7|D],}||kr•|j tdƒ|ƒq•q•WnWn{t*k r}|j+t+j,kr|j tdƒƒqG|j tdƒ|ƒn*t-k rF}|j td ƒ|ƒnX|||fS("s…Returns 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_hashRLRtRut set_attrsRr((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pytverifys¼ $   %  !                      cCsêy|jd}Wntk r%dSXd|jkr9dS|j|jjƒƒ}|dkrk|sgtS|Stjj|ƒ}t }|rKt j ||ƒ\}} } } t j |ƒ\} } }| rÚ| rÚ| | k}nt}|j rK|rK|jrK|j j|jjkrK|rDtj|d|ƒ\}}|| krDdSnt Sn|rl|rltjj|ƒ}n|ræ|r¥|s‡|}ntj|d|ƒ\}}n| s¸|| krÌ|d krÈ|StS| ræ|| krætSnt S( sÅReturn 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 NR¢R"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.7/vendor-packages/pkg/actions/file.pyRBÂsZ            cCs¬|jr tSddlm}|jjj|ƒdk}|o_|o_d|jko_d|jk}|r’tj ||dtj ƒ\}}}} ntj ||ƒ\} } } } |s¿t}n3|ræ| dksÝ| dkræt}n | | k}|rC| s ||krCd|jks<|j s<|j j|j jkrztSn7|rz|j|jjƒƒ}tjj|ƒsztSn|j||ƒ}|dkr¨|tkr¨tStS(Niÿÿÿÿ(tCONTENT_UPDATE_POLICYs when-requiredR¢R~R (RRtpkg.client.imageconfigR»R tcfgtget_policy_strR2RNR¬R’R0R?R7R­R RRRRRBR(RRRR»tuse_content_hashtbothelftcommon_elf_attrtcommon_elfhashtcommon_orig_elfhashtcommon_elf_funcR±R²R³R´R°RRf((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pyRI?s@           c Csr|j|jjƒƒ}|jjdƒ}|r`|d}|j|j|ƒ|dkr`dSnytj|tj tj BƒWn,t k r¬}|j t j kr¦dS‚nX|j r^|jjddƒjƒdkr^yTtj|ƒ\}}}tj|d|ƒ\} } | |kr+|j|ƒdSWq^tk rZ}|j t j krTdS‚q^Xn|j||ƒdS(NR!iR}R tfalseRp(R R RR2R3R!RRWR]tS_IWRITEtS_IREADRRRFR7R‡RNROR=R—R@R™t remove_fsobj( RRRR!tremoveRiRnRoRpR¸R¹((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pyRÉ~s6   !    cCs@d|jkr'd|jkr't}ntjj||d|ƒS(NR¢tcmp_hash(R2RtgenerictActiont different(RtotherRÊ((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pyRÍ®s cCs¿dd|j|jfdd|jdfddtjj|jdƒdfddtjj|jddfg}xItjD]>}|dkr‘qyn|j|}|j d||dfƒqyW|S(swGenerates the indices needed by the search dictionary. See generic.py for a more detailed explanation.RtcontentRtbasenameRN( RR0RRRÐR2tsepRNtDEFAULT_HASH_ATTRSR‰(Rt index_listtattrR((s6/usr/lib/python2.7/vendor-packages/pkg/actions/file.pytgenerate_indices¹s &  cCs|jƒ}ytj||ƒWn1tk rS}|jtjkrJ‚nd}nX|j}||f|j|j dds.            ÿÿ×