
    I0fD                    |    d dl m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Zd	 Zh d
Zdd	 	 	 ddZy)    )annotationsN)chain)Path)package_streaming   )TemporaryDirectoryc                   ddl m} t               5 }|J t        j                  j                  |       r| }nK || |z   t        j                  j                  |d             t        j                  j                  |d      }t        j                  j                  |d      } |||       t               }t               }t        j                  |      D ]  \  }	}
}|D ]  }t        j                  j                  |	|      }t        j                  j                  ||      }t        j                  j                  ||      }t        j                  j                  |      rt        j                  j                  |      s|j                  |       t        j                  |      j                  t        j                  |      j                  k7  s|j                  |         	 d d d        | fS # 1 sw Y   xY w)Nr   )extractsrc)dest_dir	converted)apir
   r   ospathisdirjoinsetwalkrelpathislinkisfileaddstatst_size)src_file_or_foldersubjectreference_extr
   tmpdir
src_folderconverted_foldermissing_filesmismatch_sizerootdirsfilesfabsfilerpdestpaths                   ?lib/python3.12/site-packages/conda_package_handling/validate.pyvalidate_converted_files_matchr+      s    		 .!!!77==+,+J&6fV[A\]fe4J77<<<"23!#!4 		.D$ .'',,tQ/WW__Wj977<<(8"=ww~~h/77>>(3%))"-)11RWWX5F5N5NN%))"-.		... }m;;/. .s   EG:$A0G:G::Hc                 *    t        j                         S )N)hashlibblake2b     r*   hash_fnr1   -   s    ??r0   >   giduidgnamemtimeunamechksumT)strictc                  	 i }i }|rdhnt         	d	fd} ||       } ||      }g }g }||k7  rHt        ||      D ]9  }||v r||v s|j                  |       ||   ||   k7  s)|j                  |       ; | ||fS )a  
    Check that two .tar.bz2 or .conda files (either of src_file and
    reference_file can be either format) match exactly, down to the timestamps
    etc.

    Does not check outside of the info- and pkg- components of a .conda.
    (conda's metadata.json, which gives the version "2" of the format)

    If strict = True, also check for matching uid, gid, mtime, uname, gname.
    r7   c           	     L   i }t        j                  |       j                  d      rddgndg}t        | d      5 }|D ]  }t	        j
                  | ||      D ]  \  }}|j                         j                         D ci c]  \  }}|vs|| }	}}|j                         rWt               }
|j                  |      J t        fdd      D ]  }|
j                  |        |
j                         |	d<   |	||	d   <     	 d d d        |S c c}}w # 1 sw Y   |S xY w)	Nz.condainfopkgrbc                 &     j                  d      S )Ni   )read)fds   r*   <lambda>zOvalidate_converted_files_match_streaming.<locals>.get_fileset.<locals>.<lambda>Z   s    "'''2B r0   r0   digestname)r   fspathendswithopenr   stream_conda_componentget_infoitemsr   r1   extractfileiterupdate	hexdigest)filenamefileset
components
conda_file	componenttarmemberkvr;   hasherblockr@   ignore_fieldss               @r*   get_filesetz=validate_converted_files_match_streaming.<locals>.get_filesetL   s3   (*		((;(D(DX(Nfe_UZT[
(D! 	1Z' 1	#4#K#Kj)$ 1KC .4__->-D-D-FaTQ!S`J`AqDaDa}}!( __V4!~-~%)*BC%H 1E"MM%01 *0)9)9);X,0GDL)11	1$  b	1$ s%   AD DDA6DDD#)rN   
str | Path)IGNORE_FIELDSr   append)
r   	referencer8   
source_setreference_setrZ   missing
mismatchedfilerY   s
            @r*   (validate_converted_files_match_streamingrd   ;   s     JM"(XJmM. S!J	*MGJ]"*m4 	(DJ&4=+@t$D!]4%88!!$'		( ##r0   ) )r   r[   r^   r[   )
__future__r   r-   r   	itertoolsr   pathlibr   conda_package_streamingr   utilsr   r+   r1   r\   rd   r/   r0   r*   <module>rk      sK    "  	   5 % 02<@ 7;5$	5$ *5$r0   