Browse Source

Simplify dataset path construction

Matthias Vogelgesang 7 years ago
parent
commit
905d061787
2 changed files with 6 additions and 5 deletions
  1. 3 0
      nova/fs.py
  2. 3 5
      nova/views.py

+ 3 - 0
nova/fs.py

@@ -29,3 +29,6 @@ class Filesystem(object):
                     total_size += os.stat(path).st_size
 
         return num_files, total_size
+
+    def path_of(self, dataset):
+        return os.path.join(self.path, dataset.path)

+ 3 - 5
nova/views.py

@@ -246,7 +246,7 @@ def delete(dataset_id=None):
     dataset, access = result
 
     if dataset:
-        shutil.rmtree(os.path.join(app.config['NOVA_ROOT_PATH'], dataset.path))
+        shutil.rmtree(fs.path_of(dataset))
         db.session.delete(dataset)
         db.session.delete(access)
         db.session.commit()
@@ -263,7 +263,7 @@ def upload(dataset_id):
             filter(Dataset.id == dataset_id).first()
 
     f = io.BytesIO(request.data)
-    memtar.extract_tar(f, os.path.join(app.config['NOVA_ROOT_PATH'], dataset.path))
+    memtar.extract_tar(f, fs.path_of(dataset))
     return ''
 
 
@@ -275,9 +275,7 @@ def clone(dataset_id):
             filter(Access.dataset_id == dataset_id).\
             filter(Dataset.id == dataset_id).first()
 
-    root = app.config['NOVA_ROOT_PATH']
-    path = os.path.join(root, dataset.path)
-    fileobj = memtar.create_tar(path)
+    fileobj = memtar.create_tar(fs.path_of(dataset))
     fileobj.seek(0)
 
     def generate():