Skip to content

Commit b41fa85

Browse files
committed
Rework move_copy/intra_move_copy
Clarifies the code used to check if the move or copy can be don on the provider, or if waterbutler needs to do it. Also refactors a function that had a bit of a weird signature so we don't need a comment justifying it.
1 parent 8bc742f commit b41fa85

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

waterbutler/server/api/v1/provider/movecopy.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,12 @@ async def move_or_copy(self):
134134
)
135135
self.dest_path = await self.dest_provider.validate_path(**self.json)
136136

137-
if not getattr(self.provider, 'can_intra_' + provider_action)(self.dest_provider, self.path):
138-
# this weird signature syntax courtesy of py3.4 not liking trailing commas on kwargs
139-
conflict = self.json.get('conflict', DEFAULT_CONFLICT)
140-
result = await getattr(tasks, provider_action).adelay(
141-
rename=self.json.get('rename'),
142-
conflict=conflict,
143-
request=remote_logging._serialize_request(self.request),
144-
*self.build_args()
145-
)
146-
metadata, created = await tasks.wait_on_celery(result)
147-
else:
137+
if getattr(self.provider, 'can_intra_' + provider_action)(self.dest_provider, self.path):
138+
# The operation can be don internally to the provider. This would
139+
# be preferred for most operations because it reduces waterbutler's
140+
# bandwith utilization and keeps resources free. Not all providers
141+
# support this, hence the check (Implemented on a provider to
142+
# provider basis).
148143
metadata, created = (
149144
await tasks.backgrounded(
150145
getattr(self.provider, provider_action),
@@ -155,6 +150,20 @@ async def move_or_copy(self):
155150
conflict=self.json.get('conflict', DEFAULT_CONFLICT),
156151
)
157152
)
153+
else:
154+
# This operation cannot be done inside of the service, using an
155+
# `intra_move` or `intra_copy`. The operation should do the default
156+
# routine of a copy followed by a delete.
157+
conflict = self.json.get('conflict', DEFAULT_CONFLICT)
158+
src_arg, dest_arg = self.build_args()
159+
result = await getattr(tasks, provider_action).adelay(
160+
src_arg,
161+
dest_arg,
162+
rename=self.json.get('rename'),
163+
conflict=conflict,
164+
request=remote_logging._serialize_request(self.request)
165+
)
166+
metadata, created = await tasks.wait_on_celery(result)
158167

159168
self.dest_meta = metadata
160169

0 commit comments

Comments
 (0)