HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/hashcache.cpython-39.pyc
a

�*�^a+�@stddlmZdZddlZddlZddlZddlmZmZm	Z
mZmZddl
mZmZdZdZdZGd	d
�d
e�ZdS)�)�absolute_imports### bzr hashcache v5
N�)�
atomicfile�errors�filters�osutils�trace)�	text_type�	viewitems��c@sjeZdZdZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Z	dd�Z
dd�Zdd�Zdd�Z
ddd�ZdS)�	HashCachea{Cache for looking up file SHA-1.

    Files are considered to match the cached value if the fingerprint
    of the file has not changed.  This includes its mtime, ctime,
    device number, inode number, and size.  This should catch
    modifications or replacement of the file by a new one.

    This may not catch modifications that do not change the file's
    size and that occur within the resolution window of the
    timestamps.  To handle this we specifically do not cache files
    which have changed since the start of the present second, since
    they could undetectably change again.

    This scheme may fail if the machine's clock steps backwards.
    Don't do that.

    This does not canonicalize the paths passed in; that should be
    done by the caller.

    _cache
        Indexed by path, points to a two-tuple of the SHA-1 of the file.
        and its fingerprint.

    stat_count
        number of times files have been statted

    hit_count
        number of times files have been retrieved from the cache, avoiding a
        re-read

    miss_count
        number of misses (times files have been completely re-read)
    FNcCsXt|t�std��||_d|_d|_d|_d|_d|_d|_	i|_
||_||_||_
dS)aICreate a hash cache in base dir, and set the file mode to mode.

        :param content_filter_stack_provider: a function that takes a
            path (relative to the top of the tree) and a file-id as
            parameters and returns a stack of ContentFilters.
            If None, no content filtering is performed.
        z#Base dir for hashcache must be textrN)�
isinstancer	�
ValueError�root�	hit_count�
miss_count�
stat_count�danger_count�
removed_count�update_count�_cache�_mode�_cache_file_name�_filter_provider)�selfr�cache_file_name�modeZcontent_filter_stack_provider�r�2/usr/lib/python3/dist-packages/breezy/hashcache.py�__init__[s	
zHashCache.__init__cCs|jS�N)r�rrrrrrszHashCache.cache_file_namecCs|jrd|_i|_dS)zJDiscard all cached information.

        This does not reset the counters.TN)r�needs_writer"rrr�clearuszHashCache.clearcCszdd�}tt|j�|d�D]Z\}}t�|j|�}|�|�}|jd7_|rX|d|kr|jd7_d|_	|j|=qdS)z�Scan all files and remove entries where the cache entry is obsolete.

        Obsolete entries are those where the file has been modified or deleted
        since the entry was inserted.
        cSs|dddS)Nr�r)Zpath_and_cacherrr�inode_order�sz#HashCache.scan.<locals>.inode_order)�keyrTN)
�sortedr
rr�pathjoinr�_fingerprintrrr#)rr&�pathZ	cache_val�abspath�fprrr�scan}s
zHashCache.scancCs�t�|j|�}|jd7_|�||�}|sV||jvrR|jd7_d|_|j|=dS||jvrp|j|\}}nd\}}||kr�|jd7_|S|j	d7_	|t
}t�|�r�|j
dur�g}n|j
|d�}|�||�}	n:t�|��rt�|�}
t�|
�d��}	nt�d||f��|��}|t|k�s:|t|k�rl|jd7_|�r�|jd7_d|_|j|=n"|jd7_d|_|	|f|j|<|	S)z#Return the sha1 of a file.
        rTN)NN)r+zUTF-8z#file %r: unknown file stat mode: %o)rr)rrr*rrr#rr�FP_MODE_COLUMN�stat�S_ISREGr�_really_sha1_file�S_ISLNK�readlinkZ
sha_string�encoderZBzrError�_cutoff_time�FP_MTIME_COLUMN�FP_CTIME_COLUMNrr)rr+�
stat_valuer,Zfile_fpZ
cache_sha1Zcache_fprrZdigest�target�cutoffrrr�get_sha1�sR




�
�
zHashCache.get_sha1cCst�||�dS)z5Calculate the SHA1 of a file by reading the full textr)�_mod_filtersZinternal_size_sha_file_byname)rr,rrrrr2�szHashCache._really_sha1_filecCs�tj|��d|jd��v}|�t�t|j�D]J\}}|�d�d|ddg}|�	d|d�|�	d	�|�d
�
|��q,d|_Wd�n1s�0YdS)
z Write contents of cache to file.�wb)Znew_mode�utf-8�// r� s%d %d %d %d %d %dr�
�FN)rZ
AtomicFilerr�write�CACHE_HEADERr
rr5�append�joinr#)rZoutfr+�cZ	line_inforrrrD�s�

zHashCache.writec
Cs�i|_|��}zt|ddd�}Wn>ty^}z&t�d|t|��d|_WYd}~dSd}~00|��|��}|t	kr�t�d|�d|_Wd�dS|D]�}|�
d�}|d|��d	�}||jvr�t�d
|�q�|d7}||d��
d�}t|�d
k�rt�d|�q�|d}	t|	�dk�r6t�d|	�q�ttt|dd���}
|	|
f|j|<q�Wd�n1�sr0Yd|_dS)z�Reinstate cache from file.

        Overwrites existing cache.

        If the cache file has the wrong version marker, this just clears
        the cache.�rbi�)�	bufferingzfailed to open %s: %sTNz<cache header marker not found at top of %s; discarding cacher@r?zduplicated path %r in cacher%rA�zbad line in hashcache: %rr�(zbad sha1 in hashcache: %rrF)rr�open�IOErrorrZmutter�strr#�readlinerE�index�decodeZwarning�split�len�tuple�map�int)r�fn�inf�eZhdr�l�posr+�fieldsZsha1r-rrr�read�sD�

0zHashCache.readcCstt���dS)z�Return cutoff time.

        Files modified more recently than this time are at risk of being
        undetectably modified and so can't be cached.
        r%)rW�timer"rrrr6szHashCache._cutoff_timecCs`|dur,zt�|�}Wnty*YdS0t�|j�r<dS|jt|j�t|j	�|j
|j|jfSr!)�os�lstat�OSErrorr0�S_ISDIR�st_mode�st_sizerW�st_mtime�st_ctime�st_ino�st_dev)rr,r9rrrr*'s�zHashCache._fingerprint)NN)N)N)�__name__�
__module__�__qualname__�__doc__r#r rr$r.r<r2rDr^r6r*rrrrr
7s!�

G2r
)Z
__future__rrEr`r0r_�rrrr=rrZsixishr	r
r7r8r/�objectr
rrrr�<module>s