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
store: implement delta uploads in push. #940
Changes from all commits
f3d74d1
772e524
1a365d1
41faa06
5fe7c5c
8c3373c
4988574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,23 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from contextlib import contextmanager | ||
import hashlib | ||
import logging | ||
import os | ||
import shutil | ||
import subprocess | ||
import logging | ||
import sys | ||
|
||
|
||
from snapcraft.internal.errors import ( | ||
RequiredCommandFailure, | ||
RequiredCommandNotFound, | ||
RequiredPathDoesNotExist, | ||
) | ||
|
||
if sys.version_info < (3, 6): | ||
import sha3 # noqa | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be used here-- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is required to patch hashlib for sha3_384. |
||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -209,3 +215,16 @@ def requires_path_exists(path, error_fmt=None): | |
kwargs['fmt'] = error_fmt | ||
raise RequiredPathDoesNotExist(**kwargs) | ||
yield | ||
|
||
|
||
def calculate_sha3_384(path): | ||
"""Calculate sha3 384 hash, reading the file in 1MB chunks.""" | ||
blocksize = 2**20 | ||
with open(path, 'rb') as snap_file: | ||
hasher = hashlib.sha3_384() | ||
while True: | ||
buf = snap_file.read(blocksize) | ||
if not buf: | ||
break | ||
hasher.update(buf) | ||
return hasher.hexdigest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've been putting this logic in
storeapi.errors
, what are the gains of going this path?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make it clear that a specific failure in the delta infrastructure will result in a fallback to the normal path. I'd be concerned that moving that into
errors
would potentially make that less obvious, but certainly open to refactoring.