Mini Shell

Direktori : /lib/python3.6/site-packages/blivet/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/blivet/__pycache__/mounts.cpython-36.pyc

3

{)c�@stddlmZddlmZddlmZddlmZddlZej	d�Z
ddlZGdd	�d	e�Z
Gd
d�de�Ze�ZdS)�)�defaultdict�)�resolve_devspec)�util)�btrfsNZblivetc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_MountinfoCachea� Cache for info from /proc/self/mountinfo. Looks up the root of the
        mount within the filesystem using a pair of mountpoint, mount
        source as keys.

        This is a very simple helper class for MountsCache, and would
        have to be altered for general purpose use.

        Note that only info for fstype btrfs is stored within the cache,
        as MountsCache methods only require information for btrfs.
    cCs
d|_dS)N)�_cache)�self�r
�/usr/lib/python3.6/mounts.py�__init__.sz_MountinfoCache.__init__c
Cs�i}td��n}xf|D]^}|j�}|jd�}||d}|jd�sBq|d}|d}t||ddd	�}	|||	|f<qWWd
QRX|S)z9 Reads lines in /proc/self/mountinfo and builds a table. z/proc/self/mountinfo�-rr���T)�sysnameN)�open�split�index�
startswithr)
r	�cacheZ
mountinfos�lineZfieldsZseparator_index�fstype�root�
mountpoint�devspecr
r
r�
_get_cache1s



z_MountinfoCache._get_cachecCs0|jdkr|j�|_t|dd�}|jj||f�S)aO Retrieves the root of the mount within the filesystem
            that corresponds to devspec and mountpoint.

            :param str devspec: device specification
            :param str mountpoint: mountpoint
            :rtype: str or NoneType
            :returns: the root of the mount within the filesystem, if available
        NT)r)rrr�get)r	rrr
r
r�get_rootFs	

z_MountinfoCache.get_rootN)�__name__�
__module__�__qualname__�__doc__rrrr
r
r
rr!src@s:eZdZdZdd�Zd
dd�Zdd�Zd	d
�Zdd�ZdS)�MountsCachez{ Cache object for system mountpoints; checks /proc/mounts and
        /proc/self/mountinfo for up-to-date information.
    cCsd|_tt�|_dS)Nr)�mounts_hashr�list�mountpoints)r	r
r
rr]szMountsCache.__init__NcCs�|j�|dk	rt|�}|dkr~|jd�r`tjj|�jd�d	}||f|jj�kr`|j||fSt	|dd�}|dk	rz|}ngS|j||fS)
aI Get mountpoints for selected device

            :param devscpec: device specification, eg. "/dev/vda1"
            :type devspec: str
            :param subvolspec: btrfs subvolume specification, eg. ID or name
            :type subvolspec: object (may be NoneType)
            :returns: list of mountpoints (path)
            :rtype: list of str or empty list

            .. note::
                Devices can be mounted on multiple paths, and paths can have multiple
                devices mounted to them (hiding previous mounts). Callers should take this into account.
        N�tmpfsz/dev�/rT)r)Nr'���)
�_cache_check�strr�os�path�realpathrr&�keysr)r	r�
subvolspec�nameZ
canon_devspecr
r
r�get_mountpointsas
zMountsCache.get_mountpointscs$|j�t�fdd�|jj�D��S)z_ Check to see if a path is already mounted

            :param str path: Path to check
        c3s|]}�|kVqdS)Nr
)�.0�p)r-r
r�	<genexpr>�sz,MountsCache.is_mountpoint.<locals>.<genexpr>)r*�anyr&�values)r	r-r
)r-r�
is_mountpoint�szMountsCache.is_mountpointc
Cs�tt�|_t�}td���}x�|D]�}y|jdd�\}}}}Wn"tk
r^tjd|�w YnX|j	d�rzt
|dd�px|}|dkr�|j||�}|dk	r�|d	d�p�tt
j�}	|j||	fj|�q�tjd
||�q |j|dfj|�q WWdQRXdS)z� Get information about mounted devices from /proc/mounts and
            /proc/self/mountinfo

            Refreshes self.mountpoints with current mountpoint information
        z/proc/mountsNrz%failed to parse /proc/mounts line: %sz/devT)rrrz@failed to obtain subvolspec for btrfs device %s at mountpoint %s)rr%r&rrr�
ValueError�log�errorrrrr+rZMAIN_VOLUME_ID�append)
r	Z	mountinfoZmountsrrrrZ_restrr0r
r
r�_get_active_mounts�s$



zMountsCache._get_active_mountscCs&tjd�}||jkr"||_|j�dS)zR Computes the SHA256 hash on /proc/mounts and updates the cache on change
        z/proc/mountsN)rZsha256_filer$r=)r	Z
sha256hashr
r
rr*�s

zMountsCache._cache_check)N)	rr r!r"rr2r8r=r*r
r
r
rr#Ws
&	r#)�collectionsrZudevr�rZ
devicelibsrZloggingZ	getLoggerr:r,�objectrr#Zmounts_cacher
r
r
r�<module>s
6c