§
    ìXÊjˆ¥  ã                   óÖ  — d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ dd	lmZmZ d
dlmZmZ d
dlmZ d
dlmZ  ej        e¦  «        Ze
d         Zg d¢Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z  ed¬¦  «         G d„ d¦  «        ¦   «         Z! ed¬¦  «         G d„ d¦  «        ¦   «         Z"d+de#ez  dz  de"fd „Z$dede%e!         fd!„Z&d"edefd#„Z'd$e(de#fd%„Z)d&e*ee(f         dedz  de(fd'„Z+d(ed)e#ddfd*„Z,dS ),z4Contains utilities to manage the HF cache directory.é    N)Údefaultdict)Ú	dataclass)ÚPath)ÚLiteral)ÚCacheNotFoundÚCorruptedCacheExceptioné   )ÚHF_HUB_CACHEÚREPO_TYPES_MAPPINGé   )Ú_shared_blobsÚlogging)Úformat_timesince)Útabulate)ÚmodelÚdatasetÚspaceÚkernel)z	.DS_Storez	Thumbs.dbzdesktop.iniT)Úfrozenc                   ó¤   — e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   e	defd	„¦   «         Z
e	defd
„¦   «         Ze	defd„¦   «         ZdS )ÚCachedFileInfoaC  Frozen data structure holding information about a single cached file.

    Args:
        file_name (`str`):
            Name of the file. Example: `config.json`.
        file_path (`Path`):
            Path of the file in the `snapshots` directory. The file path is a symlink
            referring to a blob in the `blobs` folder.
        blob_path (`Path`):
            Path of the repo-local blob entry referenced by `file_path`. The blob entry
            can itself be a symlink to the cache-wide shared blob store.
        size_on_disk (`int`):
            Size of the blob file in bytes.
        blob_last_accessed (`float`):
            Timestamp of the last time the blob file has been accessed (from any
            revision).
        blob_last_modified (`float`):
            Timestamp of the last time the blob file has been modified/created.

    > [!WARNING]
    > `blob_last_accessed` and `blob_last_modified` reliability can depend on the OS you
    > are using. See [python documentation](https://docs.python.org/3/library/os.html#os.stat_result)
    > for more details.
    Ú	file_nameÚ	file_pathÚ	blob_pathÚsize_on_diskÚblob_last_accessedÚblob_last_modifiedÚreturnc                 ó*   — t          | j        ¦  «        S )zº
        (property) Timestamp of the last time the blob file has been accessed (from any
        revision), returned as a human-readable string.

        Example: "2 weeks ago".
        )r   r   ©Úselfs    úUC:\Projects\Historical\venv\Lib\site-packages\huggingface_hub/utils/_cache_manager.pyÚblob_last_accessed_strz%CachedFileInfo.blob_last_accessed_strJ   ó   € õ   Ô 7Ñ8Ô8Ð8ó    c                 ó*   — t          | j        ¦  «        S )z¦
        (property) Timestamp of the last time the blob file has been modified, returned
        as a human-readable string.

        Example: "2 weeks ago".
        )r   r   r    s    r"   Úblob_last_modified_strz%CachedFileInfo.blob_last_modified_strT   r$   r%   c                 ó*   — t          | j        ¦  «        S )zi
        (property) Size of the blob file as a human-readable string.

        Example: "42.2K".
        ©Ú_format_sizer   r    s    r"   Úsize_on_disk_strzCachedFileInfo.size_on_disk_str^   ó   € õ ˜DÔ-Ñ.Ô.Ð.r%   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__r   ÚintÚfloatÚpropertyr#   r'   r+   © r%   r"   r   r   '   sÔ   € € € € € € ðð ð2 €N€N�NØ€O€O�OØ€O€O�OØÐÐÑàÐÐÑØÐÐÑàð9¨ð 9ð 9ð 9ñ „Xð9ð ð9¨ð 9ð 9ð 9ñ „Xð9ð ð/ #ð /ð /ð /ñ „Xð/ð /ð /r%   r   c                   ó¼   — e Zd ZU dZeed<   eed<   eed<   ee	         ed<   ee         ed<   e
ed<   edefd	„¦   «         Zedefd
„¦   «         Zedefd„¦   «         ZdS )ÚCachedRevisionInfoa.  Frozen data structure holding information about a revision.

    A revision correspond to a folder in the `snapshots` folder and is populated with
    the exact tree structure as the repo on the Hub but contains only symlinks. A
    revision can be either referenced by 1 or more `refs` or be "detached" (no refs).

    Args:
        commit_hash (`str`):
            Hash of the revision (unique).
            Example: `"9338f7b671827df886678df2bdd7cc7b4f36dffd"`.
        snapshot_path (`Path`):
            Path to the revision directory in the `snapshots` folder. It contains the
            exact tree structure as the repo on the Hub.
        files: (`frozenset[CachedFileInfo]`):
            Set of [`~CachedFileInfo`] describing all files contained in the snapshot.
        refs (`frozenset[str]`):
            Set of `refs` pointing to this revision. If the revision has no `refs`, it
            is considered detached.
            Example: `{"main", "2.4.0"}` or `{"refs/pr/1"}`.
        size_on_disk (`int`):
            Sum of the blob file sizes that are symlink-ed by the revision.
        last_modified (`float`):
            Timestamp of the last time the revision has been created/modified.

    > [!WARNING]
    > `last_accessed` cannot be determined correctly on a single revision as blob files
    > are shared across revisions.

    > [!WARNING]
    > `size_on_disk` is not necessarily the sum of all file sizes because of possible
    > duplicated files. Besides, only blobs are taken into account, not the (negligible)
    > size of folders and symlinks.
    Úcommit_hashÚsnapshot_pathr   ÚfilesÚrefsÚlast_modifiedr   c                 ó*   — t          | j        ¦  «        S )z¥
        (property) Timestamp of the last time the revision has been modified, returned
        as a human-readable string.

        Example: "2 weeks ago".
        ©r   r=   r    s    r"   Úlast_modified_strz$CachedRevisionInfo.last_modified_str”   ó   € õ   Ô 2Ñ3Ô3Ð3r%   c                 ó*   — t          | j        ¦  «        S ©zn
        (property) Sum of the blob file sizes as a human-readable string.

        Example: "42.2K".
        r)   r    s    r"   r+   z#CachedRevisionInfo.size_on_disk_strž   r,   r%   c                 ó*   — t          | j        ¦  «        S )zC
        (property) Total number of files in the revision.
        )Úlenr;   r    s    r"   Únb_fileszCachedRevisionInfo.nb_files§   s   € õ
 �4”:‰ŒÐr%   N)r-   r.   r/   r0   r1   r2   r   r3   Ú	frozensetr   r4   r5   r@   r+   rF   r6   r%   r"   r8   r8   h   sç   € € € € € € ð ð  ðD ÐÐÑØÐÐÑØÐÐÑØ�^Ô$Ð$Ð$Ñ$Ø
�CŒ.ÐÐÑàÐÐÑàð4 3ð 4ð 4ð 4ñ „Xð4ð ð/ #ð /ð /ð /ñ „Xð/ð ð˜#ð ð ð ñ „Xðð ð r%   r8   c                   ó  — e Zd ZU dZeed<   eed<   eed<   eed<   eed<   e	e
         ed<   eed<   eed	<   ed
efd„¦   «         Zed
efd„¦   «         Zed
efd„¦   «         Zed
efd„¦   «         Zed
eee
f         fd„¦   «         ZdS )ÚCachedRepoInfoaP  Frozen data structure holding information about a cached repository.

    Args:
        repo_id (`str`):
            Repo id of the repo on the Hub. Example: `"google/fleurs"`.
        repo_type (`Literal["dataset", "model", "space", "kernel"]`):
            Type of the cached repo.
        repo_path (`Path`):
            Local path to the cached repo.
        size_on_disk (`int`):
            Sum of the blob file sizes in the cached repo.
        nb_files (`int`):
            Total number of blob files in the cached repo.
        revisions (`frozenset[CachedRevisionInfo]`):
            Set of [`~CachedRevisionInfo`] describing all revisions cached in the repo.
        last_accessed (`float`):
            Timestamp of the last time a blob file of the repo has been accessed.
        last_modified (`float`):
            Timestamp of the last time a blob file of the repo has been modified/created.

    > [!WARNING]
    > `size_on_disk` is not necessarily the sum of all revisions sizes because of
    > duplicated files. Besides, only blobs are taken into account, not the (negligible)
    > size of folders and symlinks.

    > [!WARNING]
    > `last_accessed` and `last_modified` reliability can depend on the OS you are using.
    > See [python documentation](https://docs.python.org/3/library/os.html#os.stat_result)
    > for more details.
    Úrepo_idÚ	repo_typeÚ	repo_pathr   rF   Ú	revisionsÚlast_accessedr=   r   c                 ó*   — t          | j        ¦  «        S )zŸ
        (property) Last time a blob file of the repo has been accessed, returned as a
        human-readable string.

        Example: "2 weeks ago".
        )r   rN   r    s    r"   Úlast_accessed_strz CachedRepoInfo.last_accessed_strÚ   rA   r%   c                 ó*   — t          | j        ¦  «        S )zŸ
        (property) Last time a blob file of the repo has been modified, returned as a
        human-readable string.

        Example: "2 weeks ago".
        r?   r    s    r"   r@   z CachedRepoInfo.last_modified_strä   rA   r%   c                 ó*   — t          | j        ¦  «        S rC   r)   r    s    r"   r+   zCachedRepoInfo.size_on_disk_strî   r,   r%   c                 ó$   — | j         › d| j        › �S )z9Canonical `type/id` identifier used across cache tooling.ú/)rK   rJ   r    s    r"   Úcache_idzCachedRepoInfo.cache_id÷   s   € ð ”.Ð1Ð1 4¤<Ð1Ð1Ð1r%   c                 ó$   — d„ | j         D ¦   «         S )zQ
        (property) Mapping between `refs` and revision data structures.
        c                 ó(   — i | ]}|j         D ]}||“ŒŒS r6   )r<   )Ú.0ÚrevisionÚrefs      r"   ú
<dictcomp>z'CachedRepoInfo.refs.<locals>.<dictcomp>  s)   € ÐVÐVÐV (ÈÌÐVÐVÀ��XÐVÐVÐVÐVr%   )rM   r    s    r"   r<   zCachedRepoInfo.refsü   s   € ð
 WÐV¨d¬nÐVÑVÔVÐVr%   N)r-   r.   r/   r0   r1   r2   ÚREPO_TYPE_Tr   r3   rG   r8   r4   r5   rP   r@   r+   rU   Údictr<   r6   r%   r"   rI   rI   ¯   sR  € € € € € € ðð ð> €L€L�LØÐÐÑØ€O€O�OØÐÐÑØ€M€M�MØÐ+Ô,Ð,Ð,Ñ,àÐÐÑØÐÐÑàð4 3ð 4ð 4ð 4ñ „Xð4ð ð4 3ð 4ð 4ð 4ñ „Xð4ð ð/ #ð /ð /ð /ñ „Xð/ð ð2˜#ð 2ð 2ð 2ñ „Xð2ð ðW�d˜3Ð 2Ð2Ô3ð Wð Wð Wñ „XðWð Wð Wr%   rI   c                   óØ   — e Zd ZU dZeed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<    e¦   «         Zee         ed<   dZ	edz  ed	<   e
d
efd„¦   «         Zdd„ZdS )ÚDeleteCacheStrategyax  Frozen data structure holding the strategy to delete cached revisions or files.

    This object is not meant to be instantiated programmatically but to be returned by
    [`~utils.HFCacheInfo.delete_revisions`] or [`~utils.HFCacheInfo.delete_files`]. See
    documentation for usage example.

    Args:
        expected_freed_size (`float`):
            Expected freed size once strategy is executed.
        blobs (`frozenset[Path]`):
            Set of blob file paths to be deleted.
        refs (`frozenset[Path]`):
            Set of reference file paths to be deleted.
        repos (`frozenset[Path]`):
            Set of entire repo paths to be deleted.
        snapshots (`frozenset[Path]`):
            Set of snapshots to be deleted (directory of symlinks).
        files (`frozenset[Path]`, *optional*):
            Set of individual snapshot entries to be deleted. Their blobs are deleted only if
            listed in `blobs`.
        cache_dir (`Path` or `None`):
            Cache directory the strategy was computed from. Used to collect shared
            blobs referenced by repo-local symlinks removed by the deletion.
    Úexpected_freed_sizeÚblobsr<   ÚreposÚ	snapshotsr;   NÚ	cache_dirr   c                 ó*   — t          | j        ¦  «        S )zt
        (property) Expected size that will be freed as a human-readable string.

        Example: "42.2K".
        )r*   r`   r    s    r"   Úexpected_freed_size_strz+DeleteCacheStrategy.expected_freed_size_str'  s   € õ ˜DÔ4Ñ5Ô5Ð5r%   c                 óT  — t          ¦   «         }| j        �¼t          j        t          j        | j        ¦  «        ¦  «        r‘t          | j        ¦  «        }| j        D ]?}|dz  }	 |                     |                     ¦   «         ¦  «         Œ0# t          $ r Y Œ<w xY w|D ]3}t          j
        || j        ¦  «        x}r|                     |¦  «         Œ4| j        D ]}|                     d¬¦  «         Œ| j        D ]}t          |d¬¦  «         Œ| j        D ]}t          |d¬¦  «         Œ| j        D ]}t          |d¬¦  «         Œ| j        D ]}t          |d	¬¦  «         Œ| j        � |D ]}t          j        || j        ¬
¦  «         Œt$                               d| j        › d�¦  «         dS )aŠ  Execute the defined strategy.

        > [!WARNING]
        > If this method is interrupted, the cache might get corrupted. Deletion order is
        > implemented so that references and symlinks are deleted before the actual blob
        > files.

        > [!WARNING]
        > This method is irreversible. If executed, cached files are erased and must be
        > downloaded again.
        Nra   T)Ú
missing_okÚrepo)Ú	path_typeÚsnapshotrZ   Úblob©rd   zCache deletion done. Saved ú.)Úsetrd   r   Úis_shared_blobs_dirÚshared_blobs_dirra   rb   ÚupdateÚiterdirÚOSErrorÚshared_blob_targetÚaddr;   ÚunlinkÚ_try_delete_pathrc   r<   Úsweep_shared_blobÚloggerÚinforf   )r!   Úshared_store_pathsÚ
blob_pathsrL   Ú	blobs_dirr   Ú
store_pathÚpaths           r"   ÚexecutezDeleteCacheStrategy.execute0  s  € õ ),©¬ÐØŒ>Ð%­-Ô*KÝÔ*¨4¬>Ñ:Ô:ñ+
ô +
Ð%õ ˜TœZ™œˆJØ!œZð ð �	Ø%¨Ñ/�	ðØ×%Ò% i×&7Ò&7Ñ&9Ô&9Ñ:Ô:Ð:Ð:øÝð ð ð Ø�Dðøøøà'ð 7ð 7�	Ý!.Ô!AÀ)ÈTÌ^Ñ!\Ô!\Ð\�:ð 7Ø&×*Ò*¨:Ñ6Ô6Ð6øð ”Jð 	)ð 	)ˆDØ�KŠK 4ˆKÑ(Ô(Ð(Ð(ð ”Jð 	5ð 	5ˆDÝ˜T¨VÐ4Ñ4Ô4Ð4Ð4ð ”Nð 	9ð 	9ˆDÝ˜T¨ZÐ8Ñ8Ô8Ð8Ð8ð ”Ið 	4ð 	4ˆDÝ˜T¨UÐ3Ñ3Ô3Ð3Ð3ð ”Jð 	5ð 	5ˆDÝ˜T¨VÐ4Ñ4Ô4Ð4Ð4ð Œ>Ð%Ø0ð Vð V�
ÝÔ/°
ÀdÄnÐUÑUÔUÐUÐUå�ŠÐQ°$Ô2NÐQÐQÐQÑRÔRÐRÐRÐRs   Á$'BÂ
BÂB)r   N)r-   r.   r/   r0   r3   r2   rG   r   r;   rd   r5   r1   rf   r�   r6   r%   r"   r_   r_     sÛ   € € € € € € ðð ð2 ÐÐÑØ�TŒ?ÐÐÑØ
�DŒ/ÐÐÑØ�TŒ?ÐÐÑØ˜ŒÐÐÑØ&˜Y™[œ[€Eˆ9�TŒ?Ð(Ð(Ñ(Ø!€Iˆt�d‰{Ð!Ð!Ñ!àð6¨ð 6ð 6ð 6ñ „Xð6ð9Sð 9Sð 9Sð 9Sð 9Sð 9Sr%   r_   c                   ó(   — e Zd ZU dZeed<   eed<   dS )ÚCachedIncompleteFileInfoaÚ  Frozen data structure holding information about a single incomplete download.

    Interrupted downloads leave `<cache>/<repo>/blobs/<etag>.incomplete` files behind.
    These are not part of any committed revision, so they are surfaced separately by
    [`scan_cache_dir`].

    Args:
        file_path (`Path`):
            Path of the `.incomplete` file in the `blobs` folder.
        size_on_disk (`int`):
            Size of the partially-downloaded file in bytes.
    r   r   N)r-   r.   r/   r0   r   r2   r3   r6   r%   r"   rƒ   rƒ   l  s3   € € € € € € ðð ð €O€O�OØÐÐÑÐÐr%   rƒ   c                   óâ   — e Zd ZU dZeed<   ee         ed<   ee         ed<   e	e
         ed<   dZedz  ed<   edefd	„¦   «         Zedefd
„¦   «         Zdedefd„Zdedefd„Zddœdedefd„ZdS )ÚHFCacheInfoa¨  Frozen data structure holding information about the entire cache-system.

    This data structure is returned by [`scan_cache_dir`] and is immutable.

    Args:
        size_on_disk (`int`):
            Physical size of the cache-system in bytes. A blob shared across repos is
            counted once, and store-only shared blobs no longer referenced by any repo are
            included. Can be smaller than the sum of the per-repo sizes.
        repos (`frozenset[CachedRepoInfo]`):
            Set of [`~CachedRepoInfo`] describing all valid cached repos found on the
            cache-system while scanning.
        incomplete_files (`frozenset[CachedIncompleteFileInfo]`):
            Set of [`~CachedIncompleteFileInfo`] describing orphaned `*.incomplete`
            files left behind by interrupted downloads.
        warnings (`list[CorruptedCacheException]`):
            List of [`~CorruptedCacheException`] that occurred while scanning the cache.
            Those exceptions are captured so that the scan can continue. Corrupted repos
            are skipped from the scan.
        cache_dir (`Path` or `None`):
            Cache directory that was scanned.

    > [!WARNING]
    > `size_on_disk` only accounts for blobs, and corrupted repos are skipped. It is a
    > physical size: unlike `CachedRepoInfo.size_on_disk`, which attributes a shared blob
    > to every repo referencing it, a shared blob is counted here only once.
    r   rb   Úincomplete_filesÚwarningsNrd   r   c                 ó*   — t          | j        ¦  «        S )zu
        (property) Physical size of the cache-system as a human-readable string.

        Example: "42.2K".
        r)   r    s    r"   r+   zHFCacheInfo.size_on_disk_str£  r,   r%   c                 ó>   — t          d„ | j        D ¦   «         ¦  «        S )z9(property) Sum of all incomplete download sizes in bytes.c              3   ó$   K  — | ]}|j         V — Œd S ©N)r   ©rX   Úfiles     r"   ú	<genexpr>z6HFCacheInfo.incomplete_size_on_disk.<locals>.<genexpr>¯  s%   è è € ÐGÐG¨�4Ô$ÐGÐGÐGÐGÐGÐGr%   )Úsumr†   r    s    r"   Úincomplete_size_on_diskz#HFCacheInfo.incomplete_size_on_disk¬  s$   € õ ÐGÐG°Ô1FÐGÑGÔGÑGÔGÐGr%   rM   c           
      óþ  — t          |¦  «        }t          t           ¦  «        }| j        D ]J}|j        D ]@}|j        |v r5||                              |¦  «         |                     |j        ¦  «         ŒAŒKt          |¦  «        dk    r0t           	                    dd 
                    |¦  «        › �¦  «         t          ¦   «         }t          ¦   «         }t          ¦   «         }t          ¦   «         }	i }
|                     ¦   «         D �]\  }}|j        |z
  }t          |¦  «        dk    r>|                     |j        ¦  «         |j        D ]}|j        D ]}|j        |
|j        <   ŒŒŒad„ |D ¦   «         }|D ]¥}|	                     |j        ¦  «         |j        D ]"}|                     |j        dz  |z  ¦  «         Œ#|j        D ]W}|j        |j        j        v r|j        |
|j        <   Œ%|j        |vr)|                     |j        ¦  «         |j        |
|j        <   ŒXŒ¦�Œt'          t)          |¦  «        t)          |¦  «        t)          |¦  «        t)          |	¦  «        t+          |
| j        ¦  «        | j        ¬¦  «        S )a’  Prepare the strategy to delete one or more revisions cached locally.

        Input revisions can be any revision hash. If a revision hash is not found in the
        local cache, a warning is thrown but no error is raised. Revisions can be from
        different cached repos since hashes are unique across repos,

        Examples:
        ```py
        >>> from huggingface_hub import scan_cache_dir
        >>> cache_info = scan_cache_dir()
        >>> delete_strategy = cache_info.delete_revisions(
        ...     "81fd1d6e7847c99f5862c9fb81387956d99ec7aa"
        ... )
        >>> print(f"Will free {delete_strategy.expected_freed_size_str}.")
        Will free 7.9K.
        >>> delete_strategy.execute()
        Cache deletion done. Saved 7.9K.
        ```

        ```py
        >>> from huggingface_hub import scan_cache_dir
        >>> scan_cache_dir().delete_revisions(
        ...     "81fd1d6e7847c99f5862c9fb81387956d99ec7aa",
        ...     "e2983b237dccf3ab4937c97fa717319a9ca1a96d",
        ...     "6c0e6080953db56375760c0471a8c5f2929baf11",
        ... ).execute()
        Cache deletion done. Saved 8.6G.
        ```

        > [!WARNING]
        > `delete_revisions` returns a [`~utils.DeleteCacheStrategy`] object that needs to
        > be executed. The [`~utils.DeleteCacheStrategy`] is not meant to be modified but
        > allows having a dry run before actually executing the deletion.
        r   z,Revision(s) not found - cannot delete them: ú, c                 ó0   — h | ]}|j         D ]	}|j        ’Œ
ŒS r6   )r;   r   )rX   rY   Úrev_files      r"   ú	<setcomp>z/HFCacheInfo.delete_revisions.<locals>.<setcomp>÷  s-   € ÐrÐrÐr°xÐckÔcqÐrÐrÐW_ Ô 2ÐrÐrÐrÐrr%   r<   )ra   r<   rb   rc   r`   rd   )ro   r   rb   rM   r9   rv   ÚremoverE   rz   ÚwarningÚjoinÚitemsrL   r;   r   r   r:   r<   Úparentsr_   rG   Ú_expected_freed_sizerd   )r!   rM   Úhashes_to_deleteÚrepos_with_revisionsri   rY   Údelete_strategy_blobsÚdelete_strategy_refsÚdelete_strategy_reposÚdelete_strategy_snapshotsÚblobs_to_unlinkÚaffected_repoÚrevisions_to_deleteÚother_revisionsr�   Úother_blob_pathsÚrevision_to_deleterZ   s                     r"   Údelete_revisionszHFCacheInfo.delete_revisions±  sð  € õF &)¨¡^¤^ÐåNYÕZ]ÑN^ÔN^Ðà”Jð 	Bð 	BˆDØ œNð Bð B�ØÔ'Ð+;Ð;Ð;Ø(¨Ô.×2Ò2°8Ñ<Ô<Ð<Ø$×+Ò+¨HÔ,@ÑAÔAÐAøðBõ
 ÐÑ Ô  1Ò$Ð$Ý�NŠNÐgÈ$Ï)Ê)ÐTdÑJeÔJeÐgÐgÑhÔhÐhå+.©5¬5ÐÝ*-©%¬%ÐÝ+.©5¬5ÐÝ/2©u¬uÐ!ð ,.ˆà2F×2LÒ2LÑ2NÔ2Nð %	Lñ %	LÑ.ˆMÐ.Ø+Ô5Ð8KÑKˆOõ �?Ñ#Ô# qÒ(Ð(Ø%×)Ò)¨-Ô*AÑBÔBÐBØ -Ô 7ð Lð L�HØ (¤ð Lð L˜Ø:>Ô:K˜¨¬Ñ7Ð7ðLàð  sÐrÀ?ÐrÑrÔrÐØ&9ð Lð LÐ"à)×-Ò-Ð.@Ô.NÑOÔOÐOð .Ô2ð Uð U�CØ(×,Ò,¨]Ô-DÀvÑ-MÐPSÑ-SÑTÔTÐTÐTð /Ô4ð Lð L�Dð *Ô7¸4¼>Ô;QÐQÐQØ:>Ô:K˜¨¬Ñ7Ø ð ”~Ð-=Ð=Ð=Ø-×1Ò1°$´.ÑAÔAÐAØ:>Ô:K˜¨¬Ñ7øðLñLõ2 #ÝÐ1Ñ2Ô2ÝÐ/Ñ0Ô0ÝÐ1Ñ2Ô2ÝÐ 9Ñ:Ô:Ý 4°_ÀdÄnÑ UÔ UØ”nð
ñ 
ô 
ð 	
r%   r;   c           	      ó€  ‡‡— t          |¦  «        Šˆfd„| j        D ¦   «         Šˆfd„‰D ¦   «         }t          d„ ‰D ¦   «         ¦  «        }t          t	          || j        ¦  «        t          |                     ¦   «         |z
  ¦  «        t          ¦   «         t          ¦   «         t          ¦   «         || j        ¬¦  «        S )a=  Prepare the strategy to delete individual cached files.

        Only the snapshot entries are removed. A blob is deleted only if no other cached file
        references it, so blobs shared with other revisions are kept. Refs and snapshot
        directories are kept as well, even if a snapshot ends up empty. To delete whole
        revisions or repos, use [`~utils.HFCacheInfo.delete_revisions`].

        Example:
        ```py
        >>> from huggingface_hub import scan_cache_dir
        >>> cache_info = scan_cache_dir()
        >>> files = [
        ...     file
        ...     for repo in cache_info.repos
        ...     if repo.repo_id == "org/model"
        ...     for revision in repo.revisions
        ...     for file in revision.files
        ...     if file.file_name == "model-Q4_K_M.gguf"
        ... ]
        >>> delete_strategy = cache_info.delete_files(*files)
        >>> print(f"Will free {delete_strategy.expected_freed_size_str}.")
        Will free 4.9G.
        >>> delete_strategy.execute()
        Cache deletion done. Saved 4.9G.
        ```
        c                 óN   •— h | ]!}|j         D ]}|j        D ]}|‰v¯|j        ’ŒŒŒ"S r6   )rM   r;   r   )rX   ri   rY   r�   Úselecteds       €r"   r•   z+HFCacheInfo.delete_files.<locals>.<setcomp>6  s`   ø€ ð 
ð 
ð 
àØ œNð
ð 
ð Ø œð	
ð 
ð Ø˜8Ð#Ð#ð	 ŒNð $Ð#Ð#Ð#Ð#r%   c                 ó<   •— i | ]}|j         ‰v¯|j         |j        “ŒS r6   )r   r   )rX   r�   Úretained_blobss     €r"   r[   z,HFCacheInfo.delete_files.<locals>.<dictcomp>=  s4   ø€ ð 
ð 
ð 
Ø26ÀdÄnÐ\jÐFjÐFjˆDŒN˜DÔ-ÐFjÐFjÐFjr%   c              3   ó$   K  — | ]}|j         V — Œd S r‹   )r   rŒ   s     r"   rŽ   z+HFCacheInfo.delete_files.<locals>.<genexpr>@  s$   è è € ÐCÐC°$˜tœ~ÐCÐCÐCÐCÐCÐCr%   )r`   ra   r<   rb   rc   r;   rd   )ro   rb   rG   r_   r›   rd   Úkeys)r!   r;   r¢   Ú
file_pathsr­   r«   s       @@r"   Údelete_fileszHFCacheInfo.delete_files  sà   øø€ õ6 �u‘:”:ˆð
ð 
ð 
ð 
àœ
ð
ñ 
ô 
ˆð
ð 
ð 
ð 
Ø:Bð
ñ 
ô 
ˆõ ÐCÐC¸(ÐCÑCÔCÑCÔCˆ
Ý"Ý 4°_ÀdÄnÑ UÔ Uå˜O×0Ò0Ñ2Ô2°ZÑ?Ñ@Ô@Ý‘”Ý‘+”+Ý‘k”kØØ”nð	
ñ 	
ô 	
ð 		
r%   r   )Ú	verbosityr²   c                óÖ   — |dk    r2t          d„ t          | j        d„ ¬¦  «        D ¦   «         g d¢¬¦  «        S t          d„ t          | j        d„ ¬¦  «        D ¦   «         g d	¢¬¦  «        S )
a}  Generate a table from the [`HFCacheInfo`] object.

        Pass `verbosity=0` to get a table with a single row per repo, with columns
        "repo_id", "repo_type", "size_on_disk", "nb_files", "last_accessed", "last_modified", "refs", "local_path".

        Pass `verbosity=1` to get a table with a row per repo and revision (thus multiple rows can appear for a single repo), with columns
        "repo_id", "repo_type", "revision", "size_on_disk", "nb_files", "last_modified", "refs", "local_path".

        Example:
        ```py
        >>> from huggingface_hub.utils import scan_cache_dir

        >>> hf_cache_info = scan_cache_dir()
        HFCacheInfo(...)

        >>> print(hf_cache_info.export_as_table())
        REPO ID                                             REPO TYPE SIZE ON DISK NB FILES LAST_ACCESSED LAST_MODIFIED REFS LOCAL PATH
        --------------------------------------------------- --------- ------------ -------- ------------- ------------- ---- --------------------------------------------------------------------------------------------------
        roberta-base                                        model             2.7M        5 1 day ago     1 week ago    main ~/.cache/huggingface/hub/models--roberta-base
        suno/bark                                           model             8.8K        1 1 week ago    1 week ago    main ~/.cache/huggingface/hub/models--suno--bark
        t5-base                                             model           893.8M        4 4 days ago    7 months ago  main ~/.cache/huggingface/hub/models--t5-base
        t5-large                                            model             3.0G        4 5 weeks ago   5 months ago  main ~/.cache/huggingface/hub/models--t5-large

        >>> print(hf_cache_info.export_as_table(verbosity=1))
        REPO ID                                             REPO TYPE REVISION                                 SIZE ON DISK NB FILES LAST_MODIFIED REFS LOCAL PATH
        --------------------------------------------------- --------- ---------------------------------------- ------------ -------- ------------- ---- -----------------------------------------------------------------------------------------------------------------------------------------------------
        roberta-base                                        model     e2da8e2f811d1448a5b465c236feacd80ffbac7b         2.7M        5 1 week ago    main ~/.cache/huggingface/hub/models--roberta-base/snapshots/e2da8e2f811d1448a5b465c236feacd80ffbac7b
        suno/bark                                           model     70a8a7d34168586dc5d028fa9666aceade177992         8.8K        1 1 week ago    main ~/.cache/huggingface/hub/models--suno--bark/snapshots/70a8a7d34168586dc5d028fa9666aceade177992
        t5-base                                             model     a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1       893.8M        4 7 months ago  main ~/.cache/huggingface/hub/models--t5-base/snapshots/a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1
        t5-large                                            model     150ebc2c4b72291e770f58e6057481c8d2ed331a         3.0G        4 5 months ago  main ~/.cache/huggingface/hub/models--t5-large/snapshots/150ebc2c4b72291e770f58e6057481c8d2ed331a
        ```

        Args:
            verbosity (`int`, *optional*):
                The verbosity level. Defaults to 0.

        Returns:
            `str`: The table as a string.
        r   c                 óÐ   — g | ]c}|j         |j        |j        d ›|j        |j        |j        d                     t          |j        ¦  «        ¦  «        t          |j
        ¦  «        g‘ŒdS )ú>12r’   )rJ   rK   r+   rF   rP   r@   r˜   Úsortedr<   r1   rL   )rX   ri   s     r"   ú
<listcomp>z/HFCacheInfo.export_as_table.<locals>.<listcomp>v  sy   € ð ð ð ð ð œØœØÔ0Ð6Ð6ØœØÔ.ØÔ.ØŸ	š	¥&¨¬Ñ"3Ô"3Ñ4Ô4Ý˜DœNÑ+Ô+ð	ðð ð r%   c                 ó   — | j         S r‹   ©rL   ©ri   s    r"   ú<lambda>z-HFCacheInfo.export_as_table.<locals>.<lambda>�  ó   € ÀDÄN€ r%   ©Úkey)úREPO IDú	REPO TYPEúSIZE ON DISKúNB FILESÚLAST_ACCESSEDÚLAST_MODIFIEDÚREFSú
LOCAL PATH)ÚrowsÚheadersc                 ó  — g | ]}}t          |j        d „ ¬¦  «        D ]c}|j        |j        |j        |j        d›|j        |j        d                     t          |j	        ¦  «        ¦  «        t          |j        ¦  «        g‘ŒdŒ~S )c                 ó   — | j         S r‹   )r9   )rY   s    r"   r»   z8HFCacheInfo.export_as_table.<locals>.<listcomp>.<lambda>œ  s
   € ÐPXÔPd€ r%   r½   rµ   r’   )r¶   rM   rJ   rK   r9   r+   rF   r@   r˜   r<   r1   r:   )rX   ri   rY   s      r"   r·   z/HFCacheInfo.export_as_table.<locals>.<listcomp>�  s¥   € ð ð ð ð Ý$*¨4¬>Ð?dÐ?dÐ$eÑ$eÔ$eðð ð !ð œØœØ Ô,Ø#Ô4Ð:Ð:Ø Ô)Ø Ô2ØŸ	š	¥&¨¬Ñ"7Ô"7Ñ8Ô8Ý˜HÔ2Ñ3Ô3ð	ðð ð ð r%   c                 ó   — | j         S r‹   r¹   rº   s    r"   r»   z-HFCacheInfo.export_as_table.<locals>.<lambda>›  r¼   r%   )r¿   rÀ   ÚREVISIONrÁ   rÂ   rÄ   rÅ   rÆ   )r   r¶   rb   )r!   r²   s     r"   Úexport_as_tablezHFCacheInfo.export_as_tableL  s¾   € ðP ˜Š>ˆ>Ýðð õ !' t¤zÐ7RÐ7RÐ SÑ SÔ Sðñ ô ð	ð 	ð 	ðñ ô ð õ4 ðð õ !' t¤zÐ7RÐ7RÐ SÑ SÔ Sðñ ô ð	ð 	ð 	ðñ ô ð r%   )r-   r.   r/   r0   r3   r2   rG   rI   rƒ   Úlistr   rd   r   r5   r1   r+   r�   r_   r¨   r   r±   rÍ   r6   r%   r"   r…   r…     sQ  € € € € € € ðð ð8 ÐÐÑØ�^Ô$Ð$Ð$Ñ$ØÐ 8Ô9Ð9Ð9Ñ9ØÐ*Ô+Ð+Ð+Ñ+Ø!€Iˆt�d‰{Ð!Ð!Ñ!àð/ #ð /ð /ð /ñ „Xð/ð ðH¨ð Hð Hð Hñ „XðHðg
¨3ð g
Ð3Fð g
ð g
ð g
ð g
ðR0
 >ð 0
Ð6Ið 0
ð 0
ð 0
ð 0
ðd 34ð \ð \ð \¨Cð \¸ð \ð \ð \ð \ð \ð \r%   r…   rd   r   c                 ó  ‡ ‡	— ‰ €t           Š t          ‰ ¦  «                             ¦   «                              ¦   «         Š ‰                      ¦   «         st          d‰ › d�‰ ¬¦  «        ‚‰                      ¦   «         rt          d‰ › d�¦  «        ‚t          ¦   «         }g }‰  	                    ¦   «         D ]¢}|j
        t          v rŒ|j
        dk    rŒ|j
        dk    rŒ)|j
        t          j        k    rt          j        |¦  «        rŒS	 |                     t!          |¦  «        ¦  «         Œw# t"          $ r}|                     |¦  «         Y d}~Œ›d}~ww xY wt          j        t          j        ‰ ¦  «        ¦  «        Š	ˆ ˆ	fd„|D ¦   «         }|t          j        ‰ ¦  «        z  }d	}|D ]/}	 ||                     ¦   «         j        z  }Œ # t.          $ r Y Œ,w xY wt1          t3          |¦  «        |t5          ‰ ¦  «        |‰ ¬
¦  «        S )a‹  Scan the entire HF cache-system and return a [`~HFCacheInfo`] structure.

    Use `scan_cache_dir` in order to programmatically scan your cache-system. The cache
    will be scanned repo by repo. If a repo is corrupted, a [`~CorruptedCacheException`]
    will be thrown internally but captured and returned in the [`~HFCacheInfo`]
    structure. Only valid repos get a proper report.

    ```py
    >>> from huggingface_hub import scan_cache_dir

    >>> hf_cache_info = scan_cache_dir()
    HFCacheInfo(
        size_on_disk=3398085269,
        repos=frozenset({
            CachedRepoInfo(
                repo_id='t5-small',
                repo_type='model',
                repo_path=PosixPath(...),
                size_on_disk=970726914,
                nb_files=11,
                revisions=frozenset({
                    CachedRevisionInfo(
                        commit_hash='d78aea13fa7ecd06c29e3e46195d6341255065d5',
                        size_on_disk=970726339,
                        snapshot_path=PosixPath(...),
                        files=frozenset({
                            CachedFileInfo(
                                file_name='config.json',
                                size_on_disk=1197
                                file_path=PosixPath(...),
                                blob_path=PosixPath(...),
                            ),
                            CachedFileInfo(...),
                            ...
                        }),
                    ),
                    CachedRevisionInfo(...),
                    ...
                }),
            ),
            CachedRepoInfo(...),
            ...
        }),
        warnings=[
            CorruptedCacheException("Snapshots dir doesn't exist in cached repo: ..."),
            CorruptedCacheException(...),
            ...
        ],
    )
    ```

    You can also print a detailed report directly from the `hf` command line using:
    ```text
    > hf cache ls
    ID                          SIZE     LAST_ACCESSED LAST_MODIFIED REFS
    --------------------------- -------- ------------- ------------- -----------
    dataset/nyu-mll/glue          157.4M 2 days ago    2 days ago    main script
    model/LiquidAI/LFM2-VL-1.6B     3.2G 4 days ago    4 days ago    main
    model/microsoft/UserLM-8b      32.1G 4 days ago    4 days ago    main

    Done in 0.0s. Scanned 6 repo(s) for a total of 3.4G.
    Got 1 warning(s) while scanning. Use -vvv to print details.
    ```

    Args:
        cache_dir (`str` or `Path`, `optional`):
            Cache directory to cache. Defaults to the default HF cache directory.

    > [!WARNING]
    > Raises:
    >
    >     `CacheNotFound`
    >       If the cache directory does not exist.
    >
    >     [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
    >       If the cache directory is a file, instead of a directory.

    Returns: a [`~HFCacheInfo`] object.
    NzCache directory not found: zM. Please use `cache_dir` argument or set `HF_HUB_CACHE` environment variable.rm   z1Scan cache expects a directory but found a file: z.lockszCACHEDIR.TAGc                 ó~   •— h | ]9}|j         D ]/}|j        D ]%}‰rt          j        |j        ‰¦  «        ­|j        ’Œ&Œ0Œ:S r‹   )rM   r;   r   ru   r   )rX   ri   rY   r�   rd   Ústore_markeds       €€r"   r•   z!scan_cache_dir.<locals>.<setcomp>  sv   ø€ ð ð ð àØœðð ð Ø”Nð	ð ð Øðõ
  -Ô?ÀÄÐPYÑZÔZÐbð	 	Œð  cÐbÐbÐbÐbr%   r   )rb   r   r†   r‡   rd   )r
   r   Ú
expanduserÚresolveÚexistsr   Úis_fileÚ
ValueErrorro   rs   ÚnameÚFILES_TO_IGNOREr   ÚSHARED_BLOBS_DIR_NAMErp   rv   Ú_scan_cached_repor   Úappendrq   Úshared_store_blob_pathsÚstatÚst_sizert   r…   rG   Ú_scan_incomplete_files)
rd   rb   r‡   rL   ÚeÚrepo_blob_pathsÚphysical_blob_pathsÚphysical_sizer   rÑ   s
   `        @r"   Úscan_cache_dirrä   «  s�  øø€ ð` ÐÝ ˆ	å�Y‘”×*Ò*Ñ,Ô,×4Ò4Ñ6Ô6€IØ×ÒÑÔð 
Ýð C¨)ð  Cð  Cð  CØð
ñ 
ô 
ð 	
ð
 ×ÒÑÔð 
Ýð YÀ	ð  Yð  Yð  Yñ
ô 
ð 	
õ "%¡¤€EØ.0€HØ×&Ò&Ñ(Ô(ð ð ˆ	ØŒ>�_Ð,Ð,ØØŒ>˜XÒ%Ð%ØØŒ>˜^Ò+Ð+ØØŒ>�]Ô@Ò@Ð@Å]ÔEfÐgpÑEqÔEqÐ@Øð	Ø�IŠIÕ'¨	Ñ2Ô2Ñ3Ô3Ð3Ð3øÝ&ð 	ð 	ð 	Ø�OŠO˜AÑÔÐÐÐÐÐÐøøøøð	øøøõ
 !Ô4µ]Ô5SÐT]Ñ5^Ô5^Ñ_Ô_€Lðð ð ð ð àðñ ô €Oð *­MÔ,QÐR[Ñ,\Ô,\Ñ\ÐØ€MØ(ð ð ˆ	ð	Ø˜YŸ^š^Ñ-Ô-Ô5Ñ5ˆMˆMøÝð 	ð 	ð 	ØˆDð	øøøõ Ý˜ÑÔØ"Ý/°	Ñ:Ô:ØØðñ ô ð s*   Ä"D*Ä*
EÄ4EÅEÆ)GÇ
GÇGc                 ó
  — t          ¦   «         }|                      d¦  «        D ]Q}	 |                     ¦   «         j        }n# t          $ r Y Œ)w xY w|                     t          ||¬¦  «        ¦  «         ŒRt          |¦  «        S )a,  Find orphaned `*.incomplete` partial-download files in the cache.

    Interrupted downloads leave `<cache>/<repo>/blobs/<etag>.incomplete` files behind.
    These are not part of any committed revision, so they are reported separately in the
    [`~HFCacheInfo`] returned by [`scan_cache_dir`].
    z*/blobs/*.incomplete)r   r   )ro   ÚglobrÝ   rÞ   rt   rv   rƒ   rG   )rd   r;   r€   r   s       r"   rß   rß   5  s“   € õ ,/©5¬5€EØ—’Ð5Ñ6Ô6ð Wð Wˆð	ØŸ9š9™;œ;Ô.ˆLˆLøÝð 	ð 	ð 	ØˆHð	øøøà�	Š	Õ*°TÈÐUÑUÔUÑVÔVÐVÐVÝ�UÑÔÐs   §AÁ
AÁArL   c                 ó  ‡— |                       ¦   «         st          d| › �¦  «        ‚d| j        vrt          d| › �¦  «        ‚| j                             dd¬¦  «        \  }}|                     dd¦  «        }|t
          vr+t          dt          t
          ¦  «        › d|› d	| › d
�¦  «        ‚t
          |         }i Š| dz  }| dz  }|                     ¦   «         r|                      ¦   «         st          d|› �¦  «        ‚t          t          ¦  «        }|                     ¦   «         rã| 
                    ¦   «         rt          d|› �¦  «        ‚|                     d¦  «        D ]§}|                      ¦   «         s|j        t          v rŒ%|                     |¦  «                             ¦   «         }|                     ¦   «         5 }	|	                     ¦   «         }
ddd¦  «         n# 1 swxY w Y   ||
                              |¦  «         Œ¨t          ¦   «         }|                     ¦   «         D �]8}|j        t          v rŒ| 
                    ¦   «         rt          d|› �¦  «        ‚t          ¦   «         }|                     d¦  «        D �]}|                      ¦   «         rŒ|                     ¦   «         rGt)          t*          j                             |j        t+          j        |¦  «        z  ¦  «        ¦  «        }n|}|                     ¦   «         st          d|› �¦  «        ‚|‰vr|                     ¦   «         ‰|<   |                     t7          |j        |‰|         j        |‰|         j        ‰|         j        ¬¦  «        ¦  «         �Œt?          |¦  «        dk    rtA          ˆfd„|D ¦   «         ¦  «        }n|                     ¦   «         j        }|                     tC          |j        tE          |¦  «        tE          | #                    |j        t          ¦   «         ¦  «        ¦  «        tI          ˆfd„d„ |D ¦   «         D ¦   «         ¦  «        ||¬¦  «        ¦  «         �Œ:t?          |¦  «        dk    r#t          dtK          |¦  «        › d| › d
�¦  «        ‚t?          ‰¦  «        dk    rWtA          d„ ‰ &                    ¦   «         D ¦   «         ¦  «        }tA          d„ ‰ &                    ¦   «         D ¦   «         ¦  «        }n"|                      ¦   «         }|j        }|j        }tO          t?          ‰¦  «        || |tE          |¦  «        tI          d„ ‰ &                    ¦   «         D ¦   «         ¦  «        ||¬¦  «        S )z†Scan a single cache repo and return information about it.

    Any unexpected behavior will raise a [`~CorruptedCacheException`].
    zRepo path is not a directory: z--z6Repo path is not a valid HuggingFace cache directory: r   )ÚmaxsplitrT   zRepo type must be one of z	, found `z` (z).rc   r<   z,Snapshots dir doesn't exist in cached repo: z!Refs directory cannot be a file: z**/*Nz*Snapshots folder corrupted. Found a file: zBlob missing (broken symlink): )r   r   r   r   r   r   r   c              3   ó<   •K  — | ]}‰|j                  j        V — Œd S r‹   )r   Úst_mtime)rX   r�   Ú
blob_statss     €r"   rŽ   z$_scan_cached_repo.<locals>.<genexpr>¤  s.   øè è € Ð(fÐ(fÐQU¨°D´NÔ)CÔ)LÐ(fÐ(fÐ(fÐ(fÐ(fÐ(fr%   c              3   ó2   •K  — | ]}‰|         j         V — Œd S r‹   ©rÞ   )rX   r   rë   s     €r"   rŽ   z$_scan_cached_repo.<locals>.<genexpr>­  s<   øè è € ð !ð !Ø6?�J˜yÔ)Ô1ð!ð !ð !ð !ð !ð !r%   c                 ó   — h | ]	}|j         ’Œ
S r6   )r   rŒ   s     r"   r•   z$_scan_cached_repo.<locals>.<setcomp>®  s   € ÐClÐClÐClÐW[ÀDÄNÐClÐClÐClr%   )r9   r;   r<   r   r:   r=   z-Reference(s) refer to missing commit hashes: z (c              3   ó$   K  — | ]}|j         V — Œd S r‹   )Úst_atime©rX   rÝ   s     r"   rŽ   z$_scan_cached_repo.<locals>.<genexpr>¾  ó$   è è € Ð OÐ O°4 ¤Ð OÐ OÐ OÐ OÐ OÐ Or%   c              3   ó$   K  — | ]}|j         V — Œd S r‹   )rê   rñ   s     r"   rŽ   z$_scan_cached_repo.<locals>.<genexpr>¿  rò   r%   c              3   ó$   K  — | ]}|j         V — Œd S r‹   rí   rñ   s     r"   rŽ   z$_scan_cached_repo.<locals>.<genexpr>Ì  s$   è è € ÐFÐF¨$˜œÐFÐFÐFÐFÐFÐFr%   )rF   rJ   rL   rK   rM   r   rN   r=   )(Úis_dirr   r×   ÚsplitÚreplacer   r¶   rÔ   r   ro   rÕ   ræ   rØ   Úrelative_toÚas_posixÚopenÚreadrv   rs   Ú
is_symlinkr   Úosr€   ÚabspathÚparentÚreadlinkrÝ   r   rÞ   rð   rê   rE   Úmaxr8   rG   Úpopr�   r]   ÚvaluesrI   )rL   Úrepo_type_prefixrJ   rK   Úsnapshots_pathÚ	refs_pathÚrefs_by_hashÚref_pathÚref_nameÚfr9   Úcached_revisionsÚrevision_pathÚcached_filesr   r   Úrevision_last_modifiedÚrepo_last_accessedÚrepo_last_modifiedÚ
repo_statsrë   s                       @r"   rÚ   rÚ   F  s1  ø€ ð
 ×ÒÑÔð TÝ%Ð&RÀyÐ&RÐ&RÑSÔSÐSà�9”>Ð!Ð!Ý%Ð&jÐ_hÐ&jÐ&jÑkÔkÐkà )¤× 4Ò 4°TÀAÐ 4Ñ FÔ FÑÐ�gØ�oŠo˜d CÑ(Ô(€GàÕ1Ð1Ð1Ý%Øo­Õ/AÑ(BÔ(BÐoÐoÐM]ÐoÐoÐbkÐoÐoÐoñ
ô 
ð 	
õ #Ð#3Ô4€Ià-/€Jà Ñ,€NØ˜FÑ"€Ià× Ò Ñ"Ô"ð g¨.×*?Ò*?Ñ*AÔ*Að gÝ%Ð&eÐUcÐ&eÐ&eÑfÔfÐfõ
 )4µCÑ(8Ô(8€LØ×ÒÑÔð 4ð ×ÒÑÔð 	[Ý)Ð*YÈiÐ*YÐ*YÑZÔZÐZà!Ÿš vÑ.Ô.ð 		4ð 		4ˆHà�ŠÑ Ô ð  H¤Mµ_Ð$DÐ$DØà×+Ò+¨IÑ6Ô6×?Ò?ÑAÔAˆHØ—’‘”ð ' AØŸfšf™hœh�ð'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'ð ˜Ô%×)Ò)¨(Ñ3Ô3Ð3Ð3õ 14±´ÐØ'×/Ò/Ñ1Ô1ð 6
ñ 6
ˆàÔ¥Ð0Ð0ØØ× Ò Ñ"Ô"ð 	hÝ)Ð*fÐWdÐ*fÐ*fÑgÔgÐgå‘u”uˆØ&×+Ò+¨FÑ3Ô3ð 	ñ 	ˆIà×ÒÑ!Ô!ð Øð ×#Ò#Ñ%Ô%ð &Ý ¥¤§¢°Ô1AÅBÄKÐPYÑDZÔDZÑ1ZÑ![Ô![Ñ\Ô\�	�	à%�	Ø×#Ò#Ñ%Ô%ð ]Ý-Ð.[ÐPYÐ.[Ð.[Ñ\Ô\Ð\à 
Ð*Ð*Ø(1¯ªÑ(8Ô(8�
˜9Ñ%à×ÒÝØ'œnØ'Ø!+¨IÔ!6Ô!>Ø'Ø'1°)Ô'<Ô'EØ'1°)Ô'<Ô'Eðñ ô ñ	ô 	ð 	ñ 	õ ˆ|ÑÔ˜qÒ Ð Ý%(Ð(fÐ(fÐ(fÐ(fÐYeÐ(fÑ(fÔ(fÑ%fÔ%fÐ"Ð"à%2×%7Ò%7Ñ%9Ô%9Ô%BÐ"à×ÒÝØ)Ô.Ý Ñ-Ô-Ý˜|×/Ò/°Ô0BÅCÁEÄEÑJÔJÑKÔKÝ ð !ð !ð !ð !ØClÐClÐ_kÐClÑClÔClð!ñ !ô !ñ ô ð ,Ø4ð	ñ 	ô 	ñ	
ô 	
ð 	
ñ 	
õ ˆ<ÑÔ˜1ÒÐÝ%Ø_½DÀÑ<NÔ<NÐ_Ð_ÐR[Ð_Ð_Ð_ñ
ô 
ð 	
õ ˆ:�„˜ÒÐÝ Ð OÐ O¸:×;LÒ;LÑ;NÔ;NÐ OÑ OÔ OÑOÔOÐÝ Ð OÐ O¸:×;LÒ;LÑ;NÔ;NÐ OÑ OÔ OÑOÔOÐÐà—^’^Ñ%Ô%ˆ
Ø'Ô0ÐØ'Ô0Ðõ Ý�Z‘”ØØØÝÐ,Ñ-Ô-ÝÐFÐF°*×2CÒ2CÑ2EÔ2EÐFÑFÔFÑFÔFØ(Ø(ð	ñ 	ô 	ð 	s   ÇG#Ç#G'	Ç*G'	Únumc                 óx   — t          | ¦  «        }dD ]#}t          |¦  «        dk     r	|d›|› �c S |dz  }Œ$|d›d�S )zkFormat size in bytes into a human-readable string.

    Taken from https://stackoverflow.com/a/1094933
    )Ú ÚKÚMÚGÚTÚPÚEÚZg     @�@z3.1fz.1fÚY)r4   Úabs)r  Únum_fÚunits      r"   r*   r*   Ò  sb   € õ
 �#‰JŒJ€EØ7ð ð ˆÝˆu‰:Œ:˜ÒÐØÐ(Ð( $Ð(Ð(Ð(Ð(Ð(Ø�‰ˆˆØˆ?ˆ?ˆ?ˆ?Ðr%   r¢   c                 ó¬  — |�&t          j        t          j        |¦  «        ¦  «        s!t          |                      ¦   «         ¦  «        S d}t          ¦   «         }|                      ¦   «         D ]7\  }}t          j        ||¦  «        x}r|                     |¦  «         Œ2||z  }Œ8t          | ¦  «        }|D ]}|t          j	        |||¬¦  «        z  }Œ|S )a  Expected number of bytes freed by unlinking a set of blob files.

    Regular repo blobs retain the historical logical accounting. Shared symlinks count
    their canonical payload once only when every currently valid manifest reference is
    included in the deletion plan.
    Nr   )Úblob_paths_to_deleterd   )
r   rp   rq   r�   r  ro   r™   ru   rv   Úexpected_shared_blob_freed_size)r¢   rd   r`   r|   r   r   r   r!  s           r"   r›   r›   ß  sþ   € ð Ð¥Ô AÅ-ÔB`ÐajÑBkÔBkÑ lÔ lÐÝ�?×)Ò)Ñ+Ô+Ñ,Ô,Ð,ØÐÝ$'¡E¤EÐØ#2×#8Ò#8Ñ#:Ô#:ð 0ð 0Ñˆ	�<Ý&Ô9¸)ÀYÑOÔOÐOˆ:ð 	0Ø×"Ò" :Ñ.Ô.Ð.Ð.à <Ñ/ÐÐÝ˜Ñ/Ô/ÐØ(ð 
ð 
ˆ
Ø�}ÔLØÐ-AÈYð 
ñ  
ô  
ñ 	
ÐÐð Ðr%   r€   rj   c                 ó®  — t                                d|› d| › �¦  «         	 |                      ¦   «         s|                      ¦   «         rt	          j        | ¦  «         d	S t          j        | ¦  «         d	S # t          $ r% t            	                    d|› d| › d�¦  «         Y d	S t          $ r' t            	                    d|› d| › d�d¬¦  «         Y d	S w xY w)
aF  Try to delete a local file or folder.

    If the path does not exist, error is logged as a warning and then ignored.

    Args:
        path (`Path`):
            Path to delete. Can be a file or a folder.
        path_type (`str`):
            What path are we deleting ? Only for logging purposes. Example: "snapshot".
    zDelete z: zCouldn't delete z: file not found (ú)z: permission denied (T)Úexc_infoN)rz   ÚdebugrÕ   rü   rý   r–   ÚshutilÚrmtreeÚFileNotFoundErrorr—   ÚPermissionError)r€   rj   s     r"   rx   rx   ÷  s  € õ ‡L‚LÐ.˜9Ð.Ð.¨Ð.Ð.Ñ/Ô/Ð/ð
bØ�<Š<‰>Œ>ð 	 ˜TŸ_š_Ñ.Ô.ð 	 ÝŒI�d‰OŒOˆOˆOˆOåŒM˜$ÑÔÐÐÐøÝð Pð Pð Põ 	�ŠÐN¨)ÐNÐNÀtÐNÐNÐNÑOÔOÐOÐOÐOÐOÝð bð bð bÝ�ŠÐQ¨)ÐQÐQÈ$ÐQÐQÐQÐ\`ˆÑaÔaÐaÐaÐaÐaðbøøøs   ¢<A6 Á A6 Á6+CÂ$,CÃCr‹   )-r0   rý   r'  Úcollectionsr   Údataclassesr   Úpathlibr   Útypingr   Úhuggingface_hub.errorsr   r   Ú	constantsr
   r   r  r   r   Ú_parsingr   Ú	_terminalr   Ú
get_loggerr-   rz   r\   rØ   r   r8   rI   r_   rƒ   r…   r1   rä   rG   rß   rÚ   r3   r*   r]   r›   rx   r6   r%   r"   ú<module>r4     sÝ  ðð ;Ð :à 	€	€	€	Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à IÐ IÐ IÐ IÐ IÐ IÐ IÐ Ià 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ø &Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð ð 
ˆÔ	˜HÑ	%Ô	%€àÐ;Ô<€ð <Ð;Ð;€ð €�$ÐÑÔð=/ð =/ð =/ð =/ð =/ñ =/ô =/ñ Ôð=/ð@ €�$ÐÑÔðCð Cð Cð Cð Cñ Cô Cñ ÔðCðL €�$ÐÑÔðQWð QWð QWð QWð QWñ QWô QWñ ÔðQWðh €�$ÐÑÔðdSð dSð dSð dSð dSñ dSô dSñ ÔðdSðN €�$ÐÑÔðð ð ð ð ñ ô ñ Ôðð$ €�$ÐÑÔðhð hð hð hð hñ hô hñ ÔðhðV	Gð G˜c D™j¨4Ñ/ð G¸;ð Gð Gð Gð GðT dð ¨yÐ9QÔ/Rð ð ð ð ð"I ð I¨.ð Ið Ið Ið IðX
�cð 
˜cð 
ð 
ð 
ð 
ð¨$¨t°S¨y¬/ð ÀdÈTÁkð ÐVYð ð ð ð ð0b˜4ð b¨Cð b°Dð bð bð bð bð bð br%   