Current File : //usr/lib64/python3.6/site-packages/borg/platform/__pycache__/base.cpython-36.pyc
3

up�d�$�@s.ddlZddlZddlZddlZddlmZdZeedej�Z	d&dd�Z
d'dd	�Zydd
lmZd(dd�Z
Wnek
r�d)d
d�Z
YnXdd�Zdd�Zdd�ZGdd�d�ZGdd�d�Zdd�Zd*dd�Zej�Zee�Zejd�dZejjd�Ze�sdeej�fZd d!�Zd"d#�Zd$d%�Z dS)+�N)�safe_unlinkz1.1_04�	fdatasyncFcCsdS)zn
    Saves ACL Entries

    If `numeric_owner` is True the user/group field is not preserved only uid/gid
    N�)�path�item�st�
numeric_ownerrr�/usr/lib64/python3.6/base.py�acl_getsr
cCsdS)z|
    Restore ACL Entries

    If `numeric_owner` is True the stored uid/gid is used instead
    of the user/group names
    Nr)rrrrrr	�acl_set!sr)�lchflagscCst||�dS)N)r)r�	bsd_flags�fdrrr	�	set_flags-srcCsdS)Nr)rr
rrrr	r0scCst|dd�S)zHReturn BSD-style file flags for path or stat without following symlinks.Zst_flagsr)�getattr)rrrrr	�	get_flags4srcCsdtj|tj�}zDytj|�Wn0tk
rN}z|jtjkr>�WYdd}~XnXWdtj|�XdS)N)�os�open�O_RDONLY�fsync�OSError�errnoZEINVAL�close)rrZos_errorrrr	�sync_dir9srcCsFttd�rBttd|�}ytj||||�Wntk
r@YnXdS)N�
posix_fadviseZPOSIX_FADV_)�hasattrrrrr)r�offset�lenZadvicerrr	�safe_fadviseFs
rc@sHeZdZdZddd�dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�SyncFilea(
    A file class that is supposed to enable write ordering (one way or another) and data durability after close().

    The degree to which either is possible varies with operating system, file system and hardware.

    This fallback implements a naive and slow way of doing this. On some operating systems it can't actually
    guarantee any of the above, since fsync() doesn't guarantee it. Furthermore it may not be possible at all
    to satisfy the above guarantees on some hardware or operating systems. In these cases we hope that the thorough
    checksumming implemented catches any corrupted data due to misordered, delayed or partial writes.

    Note that POSIX doesn't specify *anything* about power failures (or similar failures). A system that
    routinely loses files or corrupts file on power loss is POSIX compliant.

    Calling SyncFile(path) for an existing path will raise FileExistsError, see comment in __init__.

    TODO: Use F_FULLSYNC on OSX.
    TODO: A Windows implementation should use CreateFile with FILE_FLAG_WRITE_THROUGH.
    NF)r�binarycCsJ|rdnd}||_|dkr*t||d�|_ntj||d�|_|jj�|_dS)aJ
        Open a SyncFile.

        :param path: full path/filename
        :param fd: additionally to path, it is possible to give an already open OS-level fd
               that corresponds to path (like from os.open(path, ...) or os.mkstemp(...))
        :param binary: whether to open in binary mode, default is False.
        Zxb�xN)�mode)rr�fr�fdopen�filenor)�selfrrr r"rrr	�__init__js	zSyncFile.__init__cCs|S)Nr)r&rrr	�	__enter__{szSyncFile.__enter__cCs|j�dS)N)r)r&�exc_type�exc_val�exc_tbrrr	�__exit__~szSyncFile.__exit__cCs|jj|�dS)N)r#�write)r&�datarrr	r-�szSyncFile.writecCs6ddlm}|jj�|j|j�t|jddd�dS)z�
        Synchronize file contents. Everything written prior to sync() must become durable before anything written
        after sync().
        �)�platformrZDONTNEEDN)�r0r#�flushrrr)r&r0rrr	�sync�s
z
SyncFile.synccCsJddlm}d}ztjj|j�}|j�Wd|jj�|rD|j|�XdS)zsync() and close.r/)r0N)	r1r0rr�dirnamer3r#rr)r&r0r4rrr	r�s
zSyncFile.close)
�__name__�
__module__�__qualname__�__doc__r'r(r,r-r3rrrrr	rVsrc@s*eZdZdZd
dd�Zdd�Zdd�Zd	S)�SaveFilea�
    Update file contents atomically.

    Must be used as a context manager (defining the scope of the transaction).

    On a journaling file system the file contents are always updated
    atomically and won't become corrupted, even on power failures or
    crashes (for caveats see SyncFile).

    SaveFile can safely by used in parallel (e.g. by multiple processes) to write
    to the same target path. Whatever writer finishes last (executes the os.replace
    last) "wins" and has successfully written its content to the target path.
    Internally used temporary files are created in the target directory and are
    named <BASENAME>-<RANDOMCHARS>.tmp and cleaned up in normal and error conditions.
    FcCsB||_||_tjj|�|_tjj|�d|_d|_d|_d|_	dS)N�-)
r rrr4�dir�basename�
tmp_prefix�tmp_fd�	tmp_fnamer#)r&rr rrr	r'�szSaveFile.__init__cCsRddlm}ddlm}||jd|jdd�\|_|_|j|j|j|j	d�|_
|j
S)Nr/)r0)�mkstemp_modez.tmpi�)�prefix�suffixr;r")rr )r1r0Zhelpersr@r=r;r>r?rr r#)r&r0r@rrr	r(�s
zSaveFile.__enter__cCs�ddlm}|jj�d|_|dk	r2t|j�dSz:ytj|j|j	�Wn t
k
rht|j��YnXWd|j|j�XdS)Nr/)r0)
r1r0r#rr>rr?r�replacerrrr;)r&r)r*r+r0rrr	r,�s


zSaveFile.__exit__N)F)r5r6r7r8r'r(r,rrrr	r9�s
	r9cCst|�S)z}terminal output width of string <s>

    For western scripts, this is just len(s), but for cjk glyphs, 2 cells are used.
    )r)�srrr	�swidth�srEr1c
Csv|j�}|s|dkrtj�}ytj|ddtjdtj�}Wntjk
rPYn"Xx|D]}|drX|d}PqXW|S)zpGet fully qualified domain name from name.

    An empty argument is interpreted as meaning the local host.
    z0.0.0.0Nr�)�strip�socket�gethostnameZgetaddrinfoZ
SOCK_DGRAMZAI_CANONNAME�error)�nameZaddrsZaddrrrr	�getfqdn�s
rL�.ZBORG_HOST_IDz%s@%scCsd}tj�}t||fS)z�
    Return identification tuple (hostname, pid, thread_id) for 'us'.
    This always returns the current pid, which might be different from before, e.g. if daemonize() was used.

    Note: Currently thread_id is *always* zero.
    r)r�getpid�hostid)Z	thread_id�pidrrr	�get_process_id�srQcCst�dS)ze
    Check if the (host, pid, thread_id) combination corresponds to a potentially alive process.
    N)�NotImplementedError)�hostrPZthreadrrr	�
process_alivesrTcCst�dS)zReturn whether *pid* is alive.N)rR)rPrrr	�local_pid_alivesrU)F)F)N)N)r1)!rrrHZuuidZborg.helpersrZAPI_VERSIONrrrr
rrr�ImportErrorrrrrr9rErLrIZhostnameZfqdn�split�environ�getrOZgetnoderQrTrUrrrr	�<module>s:

	
G2