From e39fc3e3ed1ba812fa689bebd2c93501f9a19aa5 Mon Sep 17 00:00:00 2001 From: Franklyn Tackitt Date: Thu, 20 Aug 2015 16:33:19 -0700 Subject: [PATCH] Fix compatibility with old .file-hashes files boto3 uploads /some/key to bucket//some/key, leaving part of the path with "//", or a folder without a name. To remedy this, I had lstrip'd the / from the key before upload. I didn't think about the fact that boto2 works fine with this, and the old .file-hashes file would have the keys with the prefixing forward slash. This solves that --- flask_s3.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/flask_s3.py b/flask_s3.py index f165330..138a696 100644 --- a/flask_s3.py +++ b/flask_s3.py @@ -128,20 +128,21 @@ def _write_files(s3, app, static_url_loc, static_folder, files, bucket, static_folder_rel = _path_to_relative_url(static_folder) for file_path in files: asset_loc = _path_to_relative_url(file_path) - key_name = _static_folder_path(static_url_loc, static_folder_rel, - asset_loc).lstrip("/") + full_key_name = _static_folder_path(static_url_loc, static_folder_rel, + asset_loc) + key_name = full_key_name.lstrip("/") msg = "Uploading %s to %s as %s" % (file_path, bucket, key_name) logger.debug(msg) exclude = False if app.config.get('S3_ONLY_MODIFIED', False): file_hash = hash_file(file_path) - new_hashes.append((key_name, file_hash)) + new_hashes.append((full_key_name, file_hash)) - if hashes and hashes.get(key_name, None) == file_hash: + if hashes and hashes.get(full_key_name, None) == file_hash: exclude = True - if ex_keys and key_name in ex_keys or exclude: + if ex_keys and full_key_name in ex_keys or exclude: logger.debug("%s excluded from upload" % key_name) else: with open(file_path) as fp: