/
var
/
opt
/
nydus
/
ops
/
customer_local_ops
/
operating_system
/
__pycache__
/
up file
home
� <�j� � �x � d dl m Z d dlZd dlmZ d dlmZmZ d dlmZ ej e � Z G d� d� Zy)� )�datetimeN)�Path)�Any�Dict)� runCommandc �R � e Zd Zdefd�Zd� Zd� Zdededefd�Zdedeee f fd �Z y )�FileInfo� file_pathc � � t |� | _ d| _ d | _ d | _ d | _ d | _ d | _ d | _ | j � y )NF) r �path�_FileInfo__exists�_FileInfo__md5�_FileInfo__sha1�_FileInfo__sha256�_FileInfo__access�_FileInfo__modify�_FileInfo__change�_FileInfo__fetch_file_info)�selfr s �^/opt/nydus/tmp/pip-target-hb7welcc/lib/python/customer_local_ops/operating_system/file_info.py�__init__zFileInfo.__init__ sJ � ���O�� ��� ��� ������ ��� ��� ��� ���� � c �V � | j j � rd| _ | j r�dD ]Y } | j t | j � |� }t | dj | j j |� |� �[ | j t | j � � }d | _ |d | _ |d | _ y y # t $ r Y ��w xY w# t t t f$ r4}t j d| j t |� � Y d }~�rd }~ww xY w)NT)�md5�sha1�sha256z_{}__{}z(Failed to get timestamps for file %s: %s�access�modify�change)r �existsr �_get_file_hash�str�setattr�format� __class__�__name__�RuntimeError�_get_file_timestamps�IOError�OSError�LOG�errorr r r )r � hash_type� hash_value� timestamps�exs r �__fetch_file_infozFileInfo.__fetch_file_info s � ��9�9���� �D�M��=�=�6� ��!%�!4�!4�S����^�Y�!O�J��D�)�"2�"2�4�>�>�3J�3J�I�"V�Xb�c� 7� Z�!�6�6�s�4�9�9�~�F� � '�x�0�D�M�&�x�0�D�M�&�x�0�D�M� �� $� ���� !�'�7�3� Z�� � �D�d�i�i�QT�UW�QX�Y�Y�� Z�s* �AC� $C � C�C� D(�4*D#�#D(c � � | j | j | j | j | j | j | j d�S )N)r r r r r r r )r r r r r r r )r s r �to_dictzFileInfo.to_dict, s= � ��m�m��:�:��K�K��m�m��m�m��m�m��m�m� � r r r- �returnc � � |dz }t ||gdj |�� � \ }}}|dk7 r1t j d||||� t d|�d|�d|�d |�d � � �|j d� }|d j � S )z� Get the hash for a given filepath and hash type, e.g. md5, sha1, sha256 :param path: The path of the file to be hashed :param hash_type: The type of hash to perform :return: The hashed file as a string �sumz{hash_type} file)r- r z"Failed to %s hash file %s: %s (%s)z Failed to z hash file z: z (�)� )r r$ r+ r, r'