1- from ....cio .core import CorePath
1+ from ....cio .core import CorePath , a_await_or_future
22from ....lib .storage import asynfs , commonfs
3+ from ....exceptions .io import FileConflict
34from ..base_command import BaseCommand
45from . import io
56
@@ -61,11 +62,11 @@ async def download_many(self, target, objects, destination=None):
6162 handle = await self .handle_many (target , * objects )
6263 return await asynfs .write (directory , name , handle )
6364
64- async def listdir (self , path , depth = None , include_deleted = False ):
65+ async def listdir (self , path = None , depth = None , include_deleted = False ):
6566 """
6667 List Directory
6768
68- :param str path: Path
69+ :param str,optional path: Path, defaults to the Cloud Drive root
6970 :param bool,optional include_deleted: Include deleted files, defaults to False
7071 """
7172 return await io .listdir (self ._core , self .normalize (path ), depth = depth , include_deleted = include_deleted )
@@ -105,18 +106,34 @@ async def public_link(self, path, access='RO', expire_in=30):
105106 """
106107 return await io .public_link (self ._core , self .normalize (path ), access , expire_in )
107108
108- async def copy (self , * paths , destination = None , wait = False ):
109+ async def _try_with_resolver (self , func , * paths , destination = None , resolver = None , cursor = None , wait = False ):
110+ async def wrapper (resume_from = None ):
111+ ref = await func (self ._core , * paths , destination = destination , resolver = resolver , cursor = resume_from )
112+ return await a_await_or_future (self ._core , ref , wait )
113+
114+ try :
115+ return await wrapper (cursor )
116+ except FileConflict as e :
117+ if resolver :
118+ return await wrapper (e .cursor )
119+ raise
120+
121+ async def copy (self , * paths , destination = None , resolver = None , cursor = None , wait = False ):
109122 """
110123 Copy one or more files or folders
111124
112125 :param list[str] paths: List of paths
113126 :param str destination: Destination
127+ :param cterasdk.core.types.ConflictResolver resolver: Conflict resolver, defaults to ``None``
128+ :param cterasdk.common.object.Object cursor: Resume copy from cursor
114129 :param bool,optional wait: ``True`` Wait for task to complete, or ``False`` to return an awaitable task object.
115130 :returns: Task status object, or an awaitable task object
116131 :rtype: cterasdk.common.object.Object or :class:`cterasdk.lib.tasks.AwaitablePortalTask`
117132 """
118133 try :
119- return await io .copy (self ._core , * [self .normalize (path ) for path in paths ], destination = self .normalize (destination ), wait = wait )
134+ return await self ._try_with_resolver (io .copy , * [self .normalize (path ) for path in paths ],
135+ destination = self .normalize (destination ),
136+ resolver = resolver , cursor = cursor , wait = wait )
120137 except ValueError :
121138 raise ValueError ('Copy destination was not specified.' )
122139
@@ -188,7 +205,8 @@ async def rename(self, path, name, *, wait=False):
188205 :returns: Task status object, or an awaitable task object
189206 :rtype: cterasdk.common.object.Object or :class:`cterasdk.lib.tasks.AwaitablePortalTask`
190207 """
191- return await io .rename (self ._core , self .normalize (path ), name , wait = wait )
208+ ref = await io .rename (self ._core , self .normalize (path ), name )
209+ return await a_await_or_future (self ._core , ref , wait )
192210
193211 async def delete (self , * paths , wait = False ):
194212 """
@@ -199,7 +217,8 @@ async def delete(self, *paths, wait=False):
199217 :returns: Task status object, or an awaitable task object
200218 :rtype: cterasdk.common.object.Object or :class:`cterasdk.lib.tasks.AwaitablePortalTask`
201219 """
202- return await io .remove (self ._core , * [self .normalize (path ) for path in paths ], wait = wait )
220+ ref = await io .remove (self ._core , * [self .normalize (path ) for path in paths ])
221+ return await a_await_or_future (self ._core , ref , wait )
203222
204223 async def undelete (self , * paths , wait = False ):
205224 """
@@ -210,19 +229,24 @@ async def undelete(self, *paths, wait=False):
210229 :returns: Task status object, or an awaitable task object
211230 :rtype: cterasdk.common.object.Object or :class:`cterasdk.lib.tasks.AwaitablePortalTask`
212231 """
213- return await io .recover (self ._core , * [self .normalize (path ) for path in paths ], wait = wait )
232+ ref = await io .recover (self ._core , * [self .normalize (path ) for path in paths ])
233+ return await a_await_or_future (self ._core , ref , wait )
214234
215- async def move (self , * paths , destination = None , wait = False ):
235+ async def move (self , * paths , destination = None , resolver = None , cursor = None , wait = False ):
216236 """
217237 Move one or more files or folders
218238
219239 :param list[str] paths: List of paths
220240 :param str destination: Destination
241+ :param cterasdk.core.types.ConflictResolver resolver: Conflict resolver, defaults to ``None``
242+ :param cterasdk.common.object.Object cursor: Resume copy from cursor
221243 :param bool,optional wait: ``True`` Wait for task to complete, or ``False`` to return an awaitable task object.
222244 :returns: Task status object, or an awaitable task object
223245 :rtype: cterasdk.common.object.Object or :class:`cterasdk.lib.tasks.AwaitablePortalTask`
224246 """
225247 try :
226- return await io .move (self ._core , * [self .normalize (path ) for path in paths ], destination = self .normalize (destination ), wait = wait )
248+ return await self ._try_with_resolver (io .move , * [self .normalize (path ) for path in paths ],
249+ destination = self .normalize (destination ),
250+ resolver = resolver , cursor = cursor , wait = wait )
227251 except ValueError :
228252 raise ValueError ('Move destination was not specified.' )
0 commit comments