airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] branch master updated: AIRAVATA-3118 save input files with valid filename
Date Sat, 13 Jul 2019 22:52:02 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/master by this push:
     new b560b44  AIRAVATA-3118 save input files with valid filename
b560b44 is described below

commit b560b447db0c3f6f964488dcbf3a224f06c31c32
Author: Marcus Christie <machristie@apache.org>
AuthorDate: Sat Jul 13 18:51:51 2019 -0400

    AIRAVATA-3118 save input files with valid filename
---
 django_airavata/apps/api/data_products_helper.py | 4 ++--
 django_airavata/apps/api/datastore.py            | 9 ++++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/django_airavata/apps/api/data_products_helper.py b/django_airavata/apps/api/data_products_helper.py
index b8c19ec..e93131e 100644
--- a/django_airavata/apps/api/data_products_helper.py
+++ b/django_airavata/apps/api/data_products_helper.py
@@ -60,12 +60,12 @@ def is_input_file_upload(request, data_product):
 def move_input_file_upload(request, data_product, path):
     source_path = _get_replica_filepath(data_product)
     file_name = data_product.productName
-    target_path = os.path.join(path, file_name)
     full_path = datastore.move(
         data_product.ownerName,
         source_path,
         request.user.username,
-        target_path)
+        path,
+        file_name)
     _delete_data_product(data_product.ownerName, source_path)
     data_product = _save_data_product(request, full_path, name=file_name)
     return data_product
diff --git a/django_airavata/apps/api/datastore.py b/django_airavata/apps/api/datastore.py
index f5c782e..76c93cb 100644
--- a/django_airavata/apps/api/datastore.py
+++ b/django_airavata/apps/api/datastore.py
@@ -41,8 +41,15 @@ def save(username, path, file, name=None):
     return input_file_fullpath
 
 
-def move(source_username, source_path, target_username, target_path):
+def move(source_username, source_path, target_username, target_dir, file_name):
     source_full_path = path_(source_username, source_path)
+    user_data_storage = _user_data_storage(target_username)
+    # Make file_name a valid filename
+    target_path = os.path.join(target_dir,
+                               user_data_storage.get_valid_name(file_name))
+    # Get available file path: if there is an existing file at target_path
+    # create a uniquely named path
+    target_path = user_data_storage.get_available_name(target_path)
     target_full_path = path_(target_username, target_path)
     file_move_safe(source_full_path, target_full_path)
     return target_full_path


Mime
View raw message