Skip to content

Commit

Permalink
Update get_file_size() to support S3 storage backend (#3030)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackdna committed Sep 26, 2018
1 parent bd39737 commit d2c1fe9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 1 addition & 3 deletions refinery/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,7 @@ def get_file_size(self):
study__in=investigation.study_set.all(), file_uuid__isnull=False
).values_list('file_uuid', flat=True)
file_items = FileStoreItem.objects.filter(uuid__in=file_uuids)
return sum(
[item.get_file_size(report_symlinks=True) for item in file_items]
)
return sum([item.get_file_size() for item in file_items])

def share(self, group, readonly=True, readmetaonly=False):
# change: !readonly & !readmetaonly, read: readonly & !readmetaonly
Expand Down
16 changes: 6 additions & 10 deletions refinery/file_store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from django.db.models.signals import post_delete
from django.dispatch import receiver

import botocore
import celery
from django_extensions.db.fields import UUIDField

Expand Down Expand Up @@ -145,21 +146,16 @@ def get_absolute_path(self):
else:
return None

def get_file_size(self, report_symlinks=False):
"""Return the size of the file in bytes.
report_symlinks: report the size of symlinked files or not
returns zero if the file is:
- not local
- a symlink and report_symlinks=False
def get_file_size(self):
"""Return the size of the file in bytes or zero if the file is not
available
"""
if self.is_symlinked() and not report_symlinks:
return 0

try:
return self.datafile.size
except ValueError: # file is not local
return 0
except OSError as exc:
except (OSError, botocore.exceptions.ClientError,
botocore.exceptions.ParamValidationError) as exc:
# file should be there but it is not
logger.critical("Error getting size for '%s': %s", self, exc)
return 0
Expand Down

0 comments on commit d2c1fe9

Please sign in to comment.