Coverage for girder/utility/filesystem_assetstore_adapter : 91%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: utf-8 -*-
############################################################################### # Copyright 2013 Kitware Inc. # # Licensed under the Apache License, Version 2.0 ( the "License" ); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ###############################################################################
""" This assetstore type stores files on the filesystem underneath a root directory. Files are named by their SHA-512 hash, which avoids duplication of file content. """
def fileIndexFields(): """ File documents should have an index on their sha512 field. """
""" :param assetstore: The assetstore to act on. """
""" For filesystem assetstores, we just need to report the free and total space on the filesystem where the assetstore lives. """ 'free': stat.f_bavail * stat.f_frsize, 'total': stat.f_blocks * stat.f_frsize }
""" Generates a temporary file and sets its location in the upload document as tempFile. This is the file that the chunks will be appended to. """
""" Appends the chunk into the temporary file. """ # Restore the internal state of the streaming SHA-512 checksum
# This probably means the server died midway through writing last # chunk to disk, and the database record was not updated. This means # we need to update the sha512 state with the difference. with open(upload['tempFile'], 'rb') as tempFile: tempFile.seek(upload['received']) while True: data = tempFile.read(BUF_SIZE) if not data: break checksum.update(data)
# Persist the internal state of the checksum
""" Returns the size of the temp file. """
""" Moves the file into its permanent content-addressed location within the assetstore. Directory hierarchy yields 256^2 buckets. """
# Already have this file stored, just delete temp file. else: # Move the temp file to permanent location in the assetstore.
""" Returns a generator function that will be used to stream the file from disk to the response. """ raise Exception('File %s does not exist.' % path)
'attachment; filename="%s"' % file['name']
""" Deletes the file from disk if it is the only File in this assetstore with the given sha512. """ 'sha512': file['sha512'], 'assetstoreId': self.assetstore['_id'] } |