Skip to content

Commit

Permalink
In cloud upload API, handle overwriting an existing object.
Browse files Browse the repository at this point in the history
  • Loading branch information
VJalili committed May 7, 2018
1 parent 6a9ce39 commit ff42cc7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/galaxy/managers/cloud.py
Expand Up @@ -6,6 +6,7 @@
import os
import random
import string
import datetime
from cgi import FieldStorage

from galaxy.exceptions import (
Expand Down Expand Up @@ -216,7 +217,7 @@ def download(self, trans, history_id, provider, bucket, obj, credentials):
os.remove(staging_file_name)
return datasets

def upload(self, trans, history_id, provider, bucket, credentials, dataset_ids=None):
def upload(self, trans, history_id, provider, bucket, credentials, dataset_ids=None, overwrite_existing=False):
if CloudProviderFactory is None:
raise Exception(NO_CLOUDBRIDGE_ERROR_MESSAGE)
connection = self._configure_provider(provider, credentials)
Expand All @@ -228,5 +229,8 @@ def upload(self, trans, history_id, provider, bucket, credentials, dataset_ids=N
history = trans.sa_session.query(trans.app.model.History).get(history_id)
for hda in history.datasets:
if dataset_ids is None or hda.dataset.id in dataset_ids:
created_obj = bucket_obj.create_object(hda.name)
object_label = hda.name
if overwrite_existing == True and bucket_obj.get(object_label) is not None:
object_label += "-" + datetime.datetime.now().strftime("%y-%m-%d-%H-%M-%S")
created_obj = bucket_obj.create_object(object_label)
created_obj.upload_from_file(hda.dataset.get_file_name())
3 changes: 2 additions & 1 deletion lib/galaxy/webapps/galaxy/api/cloud.py
Expand Up @@ -162,5 +162,6 @@ def upload(self, trans, payload, **kwargs):
provider,
bucket,
credentials,
dataset_ids)
dataset_ids,
payload.get("overwrite_existing", False))
return 'The selected dataset(s) are uploaded successfully!'

0 comments on commit ff42cc7

Please sign in to comment.