+
    Ki  c                   s    R t ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHt RR R	 lltRR
 R lltR R ltR R ltR R ltR R ltR R ltR R ltR# )z!Module for handling the PGA cacheN)gettext)OptionalTuple)urlparse)settings)logger)merge_folderspath_containsc                0    V ^8  d   QhR\         R\        /# )   createreturn)boolstrZformat   "1/usr/lib/python3.14/site-packages/lutris/cache.py__annotate__r      s     	( 	(4 	(C 	(    c                sV   \        4       pV'       d   \        P                  P                  V4      p\        P                  P	                  V4      '       gC   \        P                  P	                  \        P                  P                  V4      4      '       d   V# \        P                  # )zReturns the directory under which Lutris caches install files. This can be specified
by the user, but defaults to a location in ~/.cache.)get_custom_cache_pathospath
expanduserisdirdirnamer   ZINSTALLER_CACHE_DIR)r
   
cache_path   & r   get_cache_pathr      sg     '(JWW''
3
77==$$bggooj6Q(R(R'''r   c          
      sT    V ^8  d   QhR\         R\         R\         R\        R\         /# )r	   urlfile_id	game_slugpreparer   r   r   r   r   r   r   r      s0      C # #  Y\ r   c                sB   \        4       p\        V 4      pVP                  P                  R4      '       d   RpMTp\        P
                  P                  WBV4      pV'       d<   \        P
                  P                  V4      '       g   \        P                  ! V4       V# )a  Return the directory used as a cache a file that will be downloaded from
a URL. You also provide the file id from the file list and the slug for
the game.

The files will be cached in a directory named after the slug, but
in a further subdirectory for the file-id; since GOG file-ids are
inconvenient for this, we special case URLs pointed to 'gog.com' here.

If 'prepare' is true, this will also create the directory.zgog.comZgog)	r   r   ZnetlocZendswithr   r   ZjoinZexistsZmakedirs)r   r   r   r   r   Z	url_partsZfolderr   s   &&&&    r   get_url_cache_pathr!      sq      !JI  ++77<<
v6Dww~~d##KKKr   c                s:    V ^8  d   QhR\         \        ,          /# r	   r   )r   r   r   r   r   r   r   3   s     . .x} .r   c                 sF    \         P                  ! R4      p V '       d   V # R# )zReturns the custom path, wether it is usable or not. Returns
None if the path is not set, so that the default INSTALLER_CACHE_DIR
should be used.pga_cache_pathN)r   Zread_setting)r   s    r   r   r   3   s"     &&'78J#:--r   c                s$    V ^8  d   QhR\         /# r"   )r   r   r   r   r   r   ;   s      T r   c                 s    \        4       p V '       g   R# \        V 4      w  rV'       d   \        P                  ! V4       V# )zTrue if the custom cache path is set and refers to a usable
directory, so that get_cache_path() will return it. The directory
does not have to exist for this, but at least its *parent* directory
does.F)r   validate_custom_cache_pathr   Zwarning)r   ZvalidZmsgs      r   has_valid_custom_cache_pathr%   ;   s2    
 '(J+J7JE
sLr   c                sh    V ^8  d   QhR\         R\        \        \        \         ,          3,          /# )r	   r   r   )r   r   r   r   r   r   r   r   r   K   s(      3 5x}9L3M r   c                sf   \         P                  P                  V 4      p \         P                  P                  V 4      '       gm   \         P                  P	                  V 4      p\         P                  P                  V4      '       d   R\        R4      V ,          3# R\        R4      V ,          3# R# )zChecks the validity of a given path; returns a flag for whether
it can be used, and an optional message for what's wrong with it,
if anything is.TzZThe cache path '%s' does not exist, but its parent does so it will be created when needed.FzNThe cache path %s does not exist, nor does its parent, so it won't be created.)TN)r   r   r   r   r   _)r   Zparentr   r   r$   r$   K   s     ##J/J77==$$,77==  l   !`   r   c                s(    V ^8  d   QhR\         RR/# )r	   r   r   Nr   r   r   r   r   r   ^   s     3 3 3 3r   c                s4    \         P                  ! RV 4       R# )z(Saves the PGA cache path to the settingsr#   N)r   Zwrite_setting)r   s   &r   save_custom_cache_pathr(   ^   s    +T2r   c                r   )r	   r   r   r    r   r   r   r   r   c   s     @ @# @$ @r   c                sR    \        4       p\        T;'       d    \        W4      4      # )zTrue if the 'path' is inside the custom cache (so we should
not causally delete it). False for files in INSTALLER_CACHE_DIR -
that is a cache, but not the custom cache, and we do delete those
files freely.)r   r   r   )r   r   r   r   is_file_in_custom_cacher)   c   s$    
 '(J
>>}Z>??r   c                s4    V ^8  d   QhR\         R\         RR/# )r	   sourcedestinationr   Nr'   r   r   r   r   r   l   s!     9 9# 9C 9D 9r   c                sb   V '       g   \        R4      h\        P                  P                  V 4      V8X  d   \        P
                  ! RW4       R# \        P                  P                  V 4      '       d   \        W4       M\        P                  ! W4       \        P                  ! RW4       R# )z"Copy a file or folder to the cachezMissing sourcezFile %s is already cached in %sNzCached %s to %s)Z
ValueErrorr   r   r   r   Zinfor   r   shutilZcopyZdebug)r*   r+   s   &&r   save_to_cacher-   l   sn    )**	wwv+-5vK	ww}}Vf*F(
LL"F8r   )F)Z__doc__r   r,   r    r&   Ztypingr   r   Zurllib.parser   Zlutrisr   Zlutris.util.logr   Zlutris.util.systemr   r   r   r!   r   r%   r$   r(   r)   r-   ) r   r   <module>r.      sI    ' 	    " !  " ;	(2. &3
@9r   