Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 ˆuAc¯ã@s¢dZddlmZdeeƒkr eZdddddgZdd lZdd l Z dd l Z dd l Z dd l Z d Z d d „Zgfd d„Zdd„Zddd„Zddd„Zddd„Zddd„Zd S)z=This module contains helper functions for dealing with files.é)Úabsolute_importÚxrangeÚ issamefileÚlinkfileÚcopyfileÚlinkorcopyfileÚoverwrite_safelyNicCs"tj|ƒ}tj|ƒ}tjj||ƒS)N)ÚosÚstatÚpathÚsamestat)Úpath1Úpath2Ús1Ús2©rú/usr/lib/python3.6/files.pyÚ _issamefile+s  rc Cs0|dkr t}y t||ƒS|k r*dSXdS)zECheck whether two paths point to the same file (i.e. are hardlinked).TFN)Ú Exceptionr)r rÚcatch_stat_exceptionsrrrr2s  cCsÀt||td�rdStjj|ƒ}tjj|ƒ}tjj|ƒ}d}xpttj ƒD]b}tj |tj |d�}ytj ||ƒWn2tk r }z|j t jkrŽn‚WYdd}~XqFXd}PqFW|r¼tj||ƒdS)zUHardlink srcpath to dstpath. Attempt to atomically replace dstpath if it exists.)rNF)ÚprefixÚdirT)rÚOSErrorr r ÚabspathÚdirnameÚbasenameÚrangeÚtempfileÚTMP_MAXÚmktempÚextsepÚlinkÚerrnoÚEEXISTÚrename)ÚsrcpathÚdstpathÚdstdnameÚdstbnameZ hardlinkedÚattemptÚ_dsttmpÚerrrr>s$    Tc Cs8t||td�rdStjj|ƒ}tjj|ƒ}tjj|ƒ}t|dƒ}tj |tjj |dd�}tj |ƒ}|rŠytj |ƒ}Wntk rˆYnXtj |j ƒt j|jƒƒd} xP| dkrö|jtƒ} y|j| ƒWq¨|jƒ|jƒtj|jƒ‚Yq¨Xq¨W|jƒ|jƒtj|j|ƒ|�r4tjƒdk�r4tj|ƒdS)z�Copy srcpath to dstpath. Abort operation if e.g. not enough space is available. Attempt to atomically replace dstpath if it exists.)rNÚrbF)rrÚdeleteÚr)rrr r rrrÚopenrZNamedTemporaryFiler r ÚfchmodÚfilenoÚS_IMODEÚst_modeÚreadÚ BLOCKSIZEÚwriteÚcloseÚunlinkÚnamer$ÚselinuxÚis_selinux_enabledÚ restorecon) r%r&Úcopy_mode_from_dstÚrun_restoreconr'r(ZsrcfileZ dsttmpfileÚsÚdatarrrr_s<         cCs^yt||ƒdStk rJ}z |jtjtjtjfkr:‚nWYdd}~XnXt||||ƒdS)ztFirst attempt to hardlink srcpath to dstpath, if hardlinking isn't possible, attempt copying srcpath to dstpath.N)rrr"ZEMLINKZEPERMZEXDEVr)r%r&r=r>r+rrrr“s Fc Csœtjj|ƒ}tjj|ƒ}d}d}|r6tjƒdkr6d}n^y&tj|ƒ\}}|dkrZtd|ƒ‚Wn6tk r’} z| j t j kr€d}n‚WYdd} ~ XnX|s´tj ||ƒ|r²tj |ƒnäd} xtt tjƒD]f} tj|tj|d�} ytj || ƒWn6tk �r"} z| j t jk�rwÄ‚WYdd} ~ XqÄX| } PqÄW| dk�rDtt jdƒ‚|�r^| �r^tj| |ƒytj| |ƒWntj| ƒ‚YnX|�r˜tj |ƒdS)zpCreate a symlink, optionally replacing dstpath atomically, optionally setting or preserving SELinux context.FNrzgetfilecon(%r) failedT)rrz/No suitable temporary symlink could be created.)r r rrr:r;Z lgetfileconÚ RuntimeErrorrr"ÚENOENTÚsymlinkr<rrrrr r#ÚIOErrorZ lsetfileconr$Úremove) r%r&ÚforceÚpreserve_contextr'r(r>ÚctxÚretr+Zdsttmpr)r*rrrÚsymlink_atomically«sV        rJcCs~tjj|ƒ}tjj|ƒ}tjj|ƒ}d}d}d} tjj|ƒ} |rPtjƒdkrPd}zÖtj |tjj |d�\}} | rÎtj |ƒ} |r�tj || j | jƒ|r¨tj|t j| jƒƒ|rÎtj|ƒ\} } | dkrÎtd|ƒ‚tj|dƒ}d}|j|ƒ|jƒd}tj| |ƒ|�r$| �rtj|| ƒn tj|ƒWd|�r8|jƒn|�rHtj|ƒ| �rxtjj| ƒ�rxytj| ƒWn YnXXdS)zÁSafely overwrite a file by creating a temporary file in the same directory, writing it, moving it over the original file, eventually preserving file mode, SELinux context and ownership.NrF)rrzgetfilecon(%r) failedÚw)r r ÚrealpathrrÚexistsr:r;rZmkstempr r ÚfchownÚst_uidÚst_gidr0r2r3Z getfileconrAÚfdopenr6r7r$Z setfileconr<Úisfiler8)r ZcontentZ preserve_moderGZpreserve_ownershipZdir_ÚbaseÚfdÚfZtmpnamerMr?rIrHrrrrésR            )TT)TT)FT)TTT)Ú__doc__Z __future__rrÚ __builtins__rrÚ__all__r r:rr"r r5rrrrrrJrrrrrÚs&   ! 5  ?