-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use sync instead of copy for blob storage #6298
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
Merged
stsewd
merged 3 commits into
readthedocs:master
from
stsewd:stsewd/sync-instead-of-copy
Oct 22, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,25 @@ def setUp(self): | |||||||
def tearDown(self): | ||||||||
shutil.rmtree(self.test_media_dir, ignore_errors=True) | ||||||||
|
||||||||
def assertFileTree(self, source, tree): | ||||||||
""" | ||||||||
Recursively check that ``source`` from storage has the same file tree as ``tree``. | ||||||||
|
||||||||
:param source: source path in storage | ||||||||
:param tree: a list of strings representing files | ||||||||
or tuples (string, list) representing directories. | ||||||||
""" | ||||||||
dirs_tree = [e for e in tree if not isinstance(e, str)] | ||||||||
|
||||||||
dirs, files = self.storage.listdir(source) | ||||||||
expected_dirs = [e[0] for e in dirs_tree] | ||||||||
expected_files = [e for e in tree if isinstance(e, str)] | ||||||||
self.assertCountEqual(dirs, expected_dirs) | ||||||||
self.assertCountEqual(files, expected_files) | ||||||||
|
||||||||
for folder, files in dirs_tree: | ||||||||
self.assertFileTree(self.storage.join(source, folder), files) | ||||||||
|
||||||||
def test_copy_directory(self): | ||||||||
self.assertFalse(self.storage.exists('files/test.html')) | ||||||||
|
||||||||
|
@@ -27,6 +46,39 @@ def test_copy_directory(self): | |||||||
self.assertTrue(self.storage.exists('files/api.fjson')) | ||||||||
self.assertTrue(self.storage.exists('files/api/index.html')) | ||||||||
|
||||||||
def test_sync_directory(self): | ||||||||
tmp_files_dir = os.path.join(tempfile.mkdtemp(), 'files') | ||||||||
shutil.copytree(files_dir, tmp_files_dir) | ||||||||
storage_dir = 'files' | ||||||||
|
||||||||
tree = [ | ||||||||
('api', ['index.html']), | ||||||||
'api.fjson', | ||||||||
'conf.py', | ||||||||
'test.html', | ||||||||
] | ||||||||
self.storage.sync_directory(tmp_files_dir, storage_dir) | ||||||||
self.assertFileTree(storage_dir, tree) | ||||||||
|
||||||||
tree = [ | ||||||||
('api', ['index.html']), | ||||||||
'conf.py', | ||||||||
'test.html', | ||||||||
] | ||||||||
os.remove(os.path.join(tmp_files_dir, 'api.fjson')) | ||||||||
self.storage.sync_directory(tmp_files_dir, storage_dir) | ||||||||
self.assertFileTree(storage_dir, tree) | ||||||||
|
||||||||
tree = [ | ||||||||
# Cloud storage generally doesn't consider empty directories to exist | ||||||||
('api', []), | ||||||||
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. I was about to fix this to delete all dirs on readthedocs.org/readthedocs/rtd_tests/tests/test_build_storage.py Lines 39 to 41 in 43463b4
|
||||||||
'conf.py', | ||||||||
'test.html', | ||||||||
] | ||||||||
shutil.rmtree(os.path.join(tmp_files_dir, 'api')) | ||||||||
self.storage.sync_directory(tmp_files_dir, storage_dir) | ||||||||
self.assertFileTree(storage_dir, tree) | ||||||||
|
||||||||
def test_delete_directory(self): | ||||||||
self.storage.copy_directory(files_dir, 'files') | ||||||||
dirs, files = self.storage.listdir('files') | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 changed this, because
set1 - set2
creates another set.not in
is O(1).