xC(ddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZmZddlmZGdd eZGd d eZGd d eZGddeZGddeZGddeZGddZGddZGddZGddZGddeZGddeZ d Z!d!Z"d"Z#d#Z$d$Z%d%Z&d&Z'Gd'd(ej(Z(e(j)Z*dS))N)abstractmethod)ThreadPoolExecutor)suppress)BinaryIODictLiteralSetTuple)helpersceZdZdS) BackendErrorN)__name__ __module__ __qualname__Y/opt/imunify360/venv/lib/python3.11/site-packages/restore_infected/backup_backends_lib.pyrrsDrrceZdZdZdS)BackendNotAuthorizedErrorzR Backup backend was't initialized properly and can't be used without auth Nrrr__doc__rrrrrs DrrceZdZdZdS)BackendNonApplicableErrorzABackup couldn't be used on the systems with current configurationNrrrrrrsKKDrrceZdZdZdS)BackendClientRequiredErrorz4Backup provider requires Client soft to be installedNrrrrrrs>>>>rrceZdZdZdS)NoSuchUserErrorz.Backup file owner is not present on the systemNrrrrrr#s8888rrceZdZdZdS)UnsupportedBackupErrorz,Backend can't recognize a backup file formatNrrrrr r 's6666rr c$eZdZdZdZdZdZdS) BaseResourcez( Base class for backup resource c|||_||_t||_t |j|_dSN)pathresource _split_pathprefixlen prefix_lenselfr%r&s r__init__zBaseResource.__init__0s4   !(++ dk**rcfd|jjt|jS)Nz <{0} for {1}>)format __class__rreprr&r,s r__repr__zBaseResource.__repr__6s.%%dn&=&*4=&9&9;; ;rcL|jt|d|jkSr$)r(r'r*r,r%s r is_relatedzBaseResource.is_related:s${k$//0@0@AAArN)rrrrr-r3r6rrrr"r"+sP+++ ;;;BBBBBrr"ceZdZdZdZdZdS)FileDataz: Class to manipulate of file from backup resource c||_||\|_|_|_|_|_||_dSr$)r&infosizemtimeuidgidmodefilename)r,r&r@s rr-zFileData.__init__DsC  ?G}} @ @ < 4:tx49! rc 6d|jjt|jt|jt|jt|jt|jt|j d|j zS)NzQ<{0}(resource={1}, filename={2}, size={3}, mtime={4}, uid={5}, gid={6}, mode={7}>z0o%03o) r/r0rr1r&r@r;r<r=r>r?r2s rr3zFileData.__repr__Lsu **0&'T]##T]##TYTZ  TXTX49$ + + rN)rrrrr-r3rrrr8r8?s<!!!      rr8ceZdZdZdZdZdZdZej ddZ d d e e d e eeffd ZdS) BackupBasec"||_||_dSr$)r%created)r,r%rEs rr-zBackupBase.__init__]s  rc"|j|jkSr$)rE)r,others r__lt__zBackupBase.__lt__bs|em++rc\d|jjt|S)Nz <{0}({1})>)r/r0rstrr2s rr3zBackupBase.__repr__es#""4>#:CIIFFFrc|jSr$)r%r2s r__str__zBackupBase.__str__hs yrcB|jD]}|dSr$) resourcesclose)r,r&s rrOzBackupBase.closeks0  H NN      rNmaxsizec|jD])}||rt||cS*tt |r$)rNr6r8FileNotFoundErrorr1r+s r file_datazBackupBase.file_datapsZ 0 0H""4(( 0$///// 0T +++r/itemsreturnctj|stj|}i}|D]}tj||jtj}tj|}tj ||j |j5}t|d5}tj |D]} ||  dddn #1swxYwYdddn #1swxYwYtj} |j} tj|| | ftj||j|jtj||j|j||<|S)Nwb)osr%isabsabspathjoinr@lstripsepdirnamer mkdirr&openreadwriteDateTimenow timestampr<utimechownr=r>chmodr?) r,rV destinationresultitem target_name target_dirfileobjtargetchunkatimer<s rrestorezBackupBase.restorexs!w}}[)) 7'//+66K 0 0D',,T]11"&99K55J M* % % %##DM22 (gtT@@ ($\'22((ELL''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( $((**4466EJ((**E H[5%. 1 1 1 H[$(DH 5 5 5 H[$) , , ,"&-F;   s6D<+-D% D<%D) )D<,D) -D<<E E )rU)rrrr-rHr3rLrO functools lru_cacherTr r8rrJrtrrrrCrC\s ,,,GGG Y&&&,,'&,S]S#XrrCceZdZdZdZdZdS)FileResourceMixinz@ Mixin class for file-based resources (tar, tar.gz, gz) NcX|jr"|jd|_dSdSr$)rprOr2s rrOzFileResourceMixin.closes5 < L   DLLL  r)rrrrrprOrrrrxrxs4G     rrxcReZdZdZdZejddZdZdS)TarResourceMixinz5 Mixin class for tar resources (tar, tar.gz) cl|jst|j|_||Sr$)rp tarfile_openr%_normalize_pathr5s r_prepzTarResourceMixin._preps1| 3' 22DL##D)))rNrPc2||} |j|}n*#t$rt t |wxYw|jtj |j |j |j |j fSr$)rrp getmemberKeyErrorrSr1r;r re fromtimestampr<r=r>r?)r,r%tar_pathtar_infos rr:zTarResourceMixin.infos::d## 0|--h77HH 0 0 0#DJJ// / 0 w/==hnMM hlHM; ;s 2'Ac||} |j|S#t$rt t |t j$r"}d|jvrt|jYd}~dSd}~wwxYw)Nzunexpected end of data) rrp extractfilerrSr1tarfile ReadErrorargsEOFError)r,r%res rrbzTarResourceMixin.opens::d## (<++H55 5 0 0 0#DJJ// /  ( ( ('1611''211111 (s14B%BB) rrrrrrurvr:rbrrrr{r{sh*** Y&&& ; ;'& ; ( ( ( ( (rr{cpeZdZdZeeedZdfd ZdZ dZ fdZ xZ S) FtpBackupBasez- Base class for backup on FTP server cdSr$r)clss r FTP_DIR_NAMEzFtpBackupBase.FTP_DIR_NAMEs  rNct||||_|ptjd|_tj|j|j|_ dS)Nz~/) superr-ftprZr% expandusertmp_dirr]rftp_dir)r,rr%rErr0s rr-zFtpBackupBase.__init__s` w''':"'"4"4T":": w||DL$2CDD rctjt|j|jtjjSr$)rZr%r]rJrr^r_r2s rrLzFtpBackupBase.__str__s4w||CMM49+;+;BGK+H+HIIIrctj|j |j|j|jS#tj$rtjd|jzYnwxYwdS)zZ :raises helpers.IsNotDirError: :raises helpers.DirNotEmptyError: zError retrieving data from %sN)r rarrretriever%FtpErrorwarningr2s r _retrievezFtpBackupBase._retrieves}  dl### H8$$TY == = H H H O;dhF G G G G G Hts$A+A.-A.cttt5t j|jddddS#1swxYwYdSr$)rrOrrSshutilrmtreer)r,r0s rrOzFtpBackupBase.closes   ' ( ( ( ( M$, ' ' ' ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (sAA!$A!r$) rrrrproperty classmethodrrr-rLrrO __classcell__)r0s@rrrs  ^[X EEEEEEJJJ   (((((((((rrc|tj}|tj}t |Sr$)rstriprZr_splittuple)r% path_lists rr'r's6 ;;rv  D 26""I   rcfd}|S)Nctj|}tdtj|_|S)N __signature__)ruupdate_wrappergetattrinspect signaturer)wrapperwrappeds r decoratorzwraps..decorators@*7G<< '(/(9'(B(B!D!Drr)rrs` rwrapsrs$ rcJtfd}d|_|S)Nc|Sr$r)rfs rrzextra..wrappersq$xrT)rextra)rrs` rrrs: 1XXXGM Nrc\fdtfdd_S)NcKtjtjt jg|Ri|d{VSr$)asyncioget_event_looprun_in_executor asyncableexecutorrupartial)rkwargsfuncs rcoroutine_functionz%asyncable..coroutine_functionsj+--==    d 4T 4 4 4V 4 4         rc|djrEttdst dt_|i|}j|_|S|i|S)Nasync_r) max_workers)poprhasattrrrrr)rr coroutinerrrs rrzasyncable..wrapper s| ::h / / 9j11 G%7A%F%F%F "**D;F;;I%)%6I " tT$V$$$rF)rr)rrrs`@@rrrsa      4[[%%%%%%[%GN Nrcfd}|S)NcRtfd_S)Nc`tjjs|i|Sr$)rZr%existstoken)rrexcrrs rrzC_backend_checker_decorator..real_decorator..wrappers57>>'-00  1d%f%% %r)rr)rrrr%s`@rreal_decoratorz2_backend_checker_decorator..real_decoratorsF q & & & & & &  &  rr)r%rrs`` r_backend_checker_decoratorrs*       rc<t|t|Sr$)rr) token_path error_msgs rbackend_auth_requiredr*s$ %j&? &J&J L LLrc<t|t|Sr$)rr) client_pathrs rbackup_client_requiredr/s$ %k&@&K&K M MMrcdeZdZiejjddiZe ddedfdZdS) TarFilezstdzstdopenrNr?rwxc |dvrtd ddlm}m}n"#t$rt jdwxYw||p||||} |j|||fi|} nc#|ttf$r0| |dkrt j dt$r| wxYwd | _ | S) zhOpen zstd compressed tar archive name for reading or writing. Appending is not allowed. rzmode must be 'r', 'w' or 'x'r) ZstdErrorZstdFilezpyzstd module is not available)level_or_option zstd_dictrznot a zstd fileF) ValueErrorpyzstdrr ImportErrorrCompressionErrortaropenOSErrorrrOr Exception _extfileobj) rnamer?rprrrrrts rrzTarFile.zstdopen:s9  & &;<< < M 2 2 2 2 2 2 2 2 2 M M M*+KLL L M( Ot +      D$::6::AA7H-    MMOOOs{{'(9:::     MMOOO   s=A##A C)rNNN) rrrrr OPEN_METHrrrrrrrr4sy / # I (+ &&m$&&&[&&&rr)+rrurrZrrabcrconcurrent.futuresr contextlibrtypingrrrr r r rrrrrrr r"r8rCrxr{rr'rrrrrrrrbr}rrrrsU 11111166666666666666     9                   ????????99999l99977777\777BBBBBBBB(        :66666666r          ( ( ( ( (( ( ( (F%(%(%(%(%(J%(%(%(P*   LLL MMM -----go---`| r