Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get_file_size() to support S3 storage backend #3030

Merged
merged 1 commit into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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