MINI MINI MANI MO
9Qc @ s d Z d d d d d g Z d d l Z d d l Z d d l Z d d l Z d d l Z d Z d Z g d
Z d Z
e e d Z e e d
Z
e e d Z e e d Z d S( s= This module contains helper functions for dealing with files.t
issamefilet linkfilet copyfilet linkorcopyfilet overwrite_safelyiNi c C s1 t j | } t j | } t j j | | S( N( t ost statt patht samestat( t path1t path2t s1t s2( ( s3 /usr/lib/python2.7/site-packages/slip/util/files.pyt _issamefile# s c C s? | t k r t } n y t | | SWn | k
r: t SXd S( sE Check whether two paths point to the same file (i.e. are hardlinked).N( t Truet ExceptionR
t False( R R
t catch_stat_exceptions( ( s3 /usr/lib/python2.7/site-packages/slip/util/files.pyR * s
c C s t | | d t r d St j j | } t j j | } t j j | } t } x t t j
D]n } t j d | t j d | } y t j
| | Wn+ t k
r } | j t j k r q qe Xt } Pqe W| r t j | | n d S( sU Hardlink srcpath to dstpath.
Attempt to atomically replace dstpath if it exists.R Nt prefixt dir( R t OSErrorR R t abspatht dirnamet basenameR t xranget tempfilet TMP_MAXt mktempt extsept linkt errnot EEXISTR t rename( t srcpatht dstpatht dstdnamet dstbnamet
hardlinkedt attemptt _dsttmpt e( ( s3 /usr/lib/python2.7/site-packages/slip/util/files.pyR 6 s$ c
C s t | | d t r d St j j | } t j j | } t j j | } t | d } t j d | t j j
d | d t } t } | r y t j
| | j t } Wq t j t f k
r q Xn | s t j
| | j n d } xa | d k rT| j t } y | j | Wq | j | j t j | j q Xq W| j | j t j | j | | rt j d k rt j | n d S( s Copy srcpath to dstpath.
Abort operation if e.g. not enough space is available. Attempt to
atomically replace dstpath if it exists.R Nt rbR R t deletet i ( R R R R R R R t openR t NamedTemporaryFileR R t shutilt copymodet nameR t Errort Nonet readt BLOCKSIZEt writet closet unlinkR t selinuxt is_selinux_enabledt
restorecon(
R! R"