This is an automated email from the ASF dual-hosted git repository.

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

commit e4aa3d4d99138634556d46628d747b1a40e077be
Author: Marcus Christie <[email protected]>
AuthorDate: Tue Apr 18 09:28:24 2023 -0400

    AIRAVATA-3694 Reset modification time when unarchiving
    
    i.e., 'touch' all of the unarchived files
---
 .../apps/admin/management/commands/unarchive_user_data.py  | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git 
a/django_airavata/apps/admin/management/commands/unarchive_user_data.py 
b/django_airavata/apps/admin/management/commands/unarchive_user_data.py
index d1d817d0..dddb35b0 100644
--- a/django_airavata/apps/admin/management/commands/unarchive_user_data.py
+++ b/django_airavata/apps/admin/management/commands/unarchive_user_data.py
@@ -1,5 +1,6 @@
 
 import os
+import pathlib
 import tarfile
 
 from django.core.management.base import BaseCommand
@@ -13,6 +14,9 @@ class Command(BaseCommand):
     def add_arguments(self, parser):
         parser.add_argument('archive_file',
                             help="Archive file (ending in .tgz) that was 
created by the archive_user_data")
+        parser.add_argument('-m', '--reset-modification',
+                            help="Set modification timestamp to current time 
for all entries in archive",
+                            action="store_true")
 
     def handle(self, *args, **options):
         with tarfile.open(options["archive_file"]) as tf:
@@ -26,3 +30,13 @@ class Command(BaseCommand):
             archive.save()
         except models.UserDataArchive.DoesNotExist:
             self.stdout.write(self.style.ERROR(f"Could not find 
UserDataArchive database record for {archive_name}"))
+
+        if options["reset_modification"]:
+            root = pathlib.Path('/')
+            with tarfile.open(options["archive_file"]) as tf:
+                for tarinfo in tf:
+                    path = root / tarinfo.path
+                    path.touch()
+            self.stdout.write("Updated modification timestamps for all 
entries")
+
+        self.stdout.write(self.style.SUCCESS(f"Successfully unarchived 
{options['archive_file']}"))

Reply via email to