HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/duplicity/backends/__pycache__/gdrivebackend.cpython-310.pyc
o

��La�=�@s~ddlmZddlZddlZddlmZddlmZddlmZddl	ZGdd�dej
j�Zej
�
de�ej
j�dg�dS)	�)�strN)�log)�util)�BackendExceptionc@s`eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
GDriveBackendz1Connect to remote store using Google Drive API V3�diPc
Cs�tjj�||�zddlm}ddlm}Wnty*}zt	dt
|���d}~wwi|_i|_i|_
i|_d|_d|jvrYddi|_d|jddi|_d	d
i|_
dd
i|_n!d|jvrvdd
i|_d	d
i|_
dd
i|_|jdd|_nt	d��|jdur�|jd|j}n|j}dtjvr�|�tjd�}|j|kr�t	d|j|f��n�dtjv�rLdtjv�rLddlm}ddlm}d}tj�tjd�r�ttjdd��
}	t�|	�}Wd�n1s�wY|r�|j �s<|r�|j!r�|j"r�|�#|��n!|�$tjddg�}
|
j%d|k�rt	d|
j%d|f��|
�&�}ttjdd��}	t�'||	�Wd�n	1�s7wY|j(|k�rKt	d|j(|f��nt	d��|dd|d�|_)|j�rb|jd}n
|j�rj|j}nd}|j�*d �}|D]a}
|
�s{�qtd!|
d"|d#}|j)�+�j,d,|d$d%d&�|j�|j�|j
�|j���-�}|�.d'g�}t/|�dk�r�|
d(|gd)�}|�0|j�|j)�+�j1d,|d*d+�|j���-�}n|d}|d*}�qt||_2i|_3dS)-Nr)�build)�CredentialszpGDrive backend requires Google API client installation.
Please read the manpage for setup details.
Exception: %s�driveID�corpora�drive�driveId�includeItemsFromAllDrivesT�supportsAllDrives�myDriveFolderID�userzVgdrive: backend requires a query paramater should either be driveID or myDriveFolderID�@�GOOGLE_SERVICE_JSON_FILEzGService account email in the JSON file (%s) does not match the URL (%s)�GOOGLE_CLIENT_SECRET_JSON_FILE�GOOGLE_CREDENTIALS_FILE)�InstalledAppFlow)�Request�rbz*https://www.googleapis.com/auth/drive.file�	client_idz;Client ID in the JSON file (%s) does not match the URL (%s)�wbzBClient ID in the credentials file (%s) does not match the URL (%s)zxGOOGLE_SERVICE_JSON_FILE or GOOGLE_CLIENT_SECRET_JSON_FILE environment variable not set. Please read the manpage to fix.�v3)�credentials�root�/zname = 'z' and 'zR' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false��files(name,id),nextPageToken)�q�pageSize�fields�filesz"application/vnd.google-apps.folder)�name�mimeType�parents�id)�bodyr#�)4�	duplicity�backend�Backend�__init__�googleapiclient.discoveryr�google.oauth2.service_accountr	�ImportErrorrr�shared_drive_corpora�shared_drive_id�shared_drive_flags_include�shared_drive_flags_support�shared_root_folder_id�
query_args�username�hostname�os�environ�from_service_account_file�service_account_email�google_auth_oauthlib.flowr�google.auth.transport.requestsr�path�exists�open�pickle�load�valid�expired�
refresh_token�refresh�from_client_secrets_file�
client_config�run_console�dumprr�splitr$�list�execute�get�len�update�create�folder�id_cache)�self�
parsed_urlrr	�errrr�token�flow�parent_folder_id�folder_names�folder_namer!�results�	file_list�
file_metadatarTr*r*�B/usr/lib/python3/dist-packages/duplicity/backends/gdrivebackend.pyr.%s����






�


�����������������������
zGDriveBackend.__init__c

Cs�ddlm}t�|�}||jvrs|j|}z7|j��jd|dd�|j���	�}|d|krK|dsK|dD]}||j
krJt�d||f�|WSq5Wn|ye}z
|j
jd	kr[�WYd}~nd}~wwt�d
||f�|j|=d||j
f}|j��jd|dd
d�|j�|j�|j�|j���	�}|�dg�}	t|	�dkr�t�d|f�n"t|	�dkr�|	dd}|	dd|j|<t�d||f�|	dSt�d|f�dS)Nr��	HttpErrorzid,size,name,parents,trashed)�fileIdr#r%�trashedr'z6GDrive backend: found file '%s' with id %s in ID cachei�zBGDrive backend: invalidating '%s' (previously ID %s) from ID cachez3name = '%s' and '%s' in parents and trashed = falsez!files(name,id,size),nextPageToken�)r!r#r"r$rz+GDrive backend: multiple files called '%s'.r(zEGDrive backend: found file '%s' with id %s on server, adding to cachez9GDrive backend: file '%s' not found in cache or on serverr*)�googleapiclient.errorsrcr�fsdecoderUrr$rPr5rOrTr�Info�resp�statusrNr2r3r4rQ�
FatalError)
rV�filenamerc�file_id�
drive_file�parent�errorr!r^r_r*r*ra�file_by_name�sv


���
�
��������������zGDriveBackend.file_by_namecCs|�|�}|durdS|dS)N�r()rr)rVrmror*r*ra�
id_by_name�s
zGDriveBackend.id_by_namecCsddlm}t�|�}|�|�}|�d�rd}nd}tj�|j	�}||j
kr+d}d}nd}d}||j	||d	�}	|durd||jgd
�}
|
�|j
�t�d|f�|j��jd|
|	d�|j��j|d
�}n t�d||df�|j��jd|	|dd�|j��j|d
�}|d|j|<dS)Nr)�MediaFileUploadz.gpgzapplication/pgp-encryptedz
text/plainT�F)�mimetype�	resumable)r%r'z&GDrive backend: creating new file '%s')r)�
media_body)�num_retriesz9GDrive backend: replacing existing file '%s' with id '%s'r()ryrdr*)�googleapiclient.httprurrhrr�endswithr:r@�getsizer%�MIN_RESUMABLE_UPLOADrTrRr3rrirr$rSr5rOrU)rV�source_path�remote_filenameruro�	mime_type�	file_sizerxrz�mediar`r*r*ra�_put�sJ



�������zGDriveBackend._putc
Cs�ddlm}|�|�}|j��jdd|di|j��}tt�	|j
�d��&}d}|||�}|durB|��\}	}|dus0Wd�dSWd�dS1sMwYdS)Nr)�MediaIoBaseDownloadrdr(rFr*)r{r�rrrr$�	get_mediar5rBrrhr%�
next_chunk)
rVr��
local_pathr�ro�request�fh�done�
downloaderrkr*r*ra�_gets
�

��"�zGDriveBackend._getcCs�d}g}	|j��jd
d|jd|jd|d�|j�|j�|j�|j���	�}||�
dg�7}|�
dd�}|dur:nqtdd	�|D��}t|j�
��D]}||vr]|�|�dur]|�|�qKt|�S)NT�'z' in parents and trashed=falser )r!r"r#�	pageTokenr$�
nextPageTokencss�|]}|dVqdS)r%Nr*)�.0�itemr*r*ra�	<genexpr>1s�z&GDriveBackend._list.<locals>.<genexpr>r*)rr$rNrT�	PAGE_SIZEr2r3r4r5rOrP�setrU�keysrr�add)rV�
page_token�drive_files�response�	filenamesrmr*r*ra�_lists<������
�
�zGDriveBackend._listcCsP|�|�}|dkrt�dt�|�f�dS|j��jdd|i|j���	�dS)Nrsz2File '%s' does not exist while trying to delete itrdr*)
rtr�Warnrrhrr$�deleter5rO)rVrmrnr*r*ra�_delete;s
�
zGDriveBackend._deletecCs2|�|�}|durd}d|iSt|d�}d|iS)N����size)rr�int)rVrmror�r*r*ra�_queryCs
�zGDriveBackend._querycCsDddlm}ddlm}t||�rtjjSt||�rtjjStjj	S)Nr)�RefreshErrorrb)
�google.auth.exceptionsr�rgrc�
isinstancer�	ErrorCode�backend_not_found�backend_permission_denied�
backend_error)rV�	operationrqr�rcr*r*ra�_error_codeKs

zGDriveBackend._error_codeN)�__name__�
__module__�__qualname__�__doc__r�r~r.rrrtr�r�r�r�r�r�r*r*r*rars
3&r�gdrive)�builtinsrr:rCr+rr�duplicity.errorsr�duplicity.backendr,r-r�register_backend�uses_netloc�extendr*r*r*ra�<module>s8