-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add support for bucket to bucket sync of the latest versions of files #165
Changes from 1 commit
de1f5aa
5702cb6
66cb55a
3eb5189
cabba13
8b5328d
f089bd9
dd3e6ec
e196a02
c1b51f9
2f0f77f
0df6236
ded4499
3a3da88
8da4823
9dba8b0
3d5a0b8
93013c1
c96d741
5b0fdd2
56c4dcb
2d6e955
a7429eb
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
import logging | ||
|
||
from ..exception import DestFileNewer | ||
from .action import LocalDeleteAction, B2DeleteAction, B2DownloadAction, B2HideAction, B2UploadAction | ||
from .action import LocalDeleteAction, B2CopyAction, B2DeleteAction, B2DownloadAction, B2HideAction, B2UploadAction | ||
from .exception import InvalidArgument | ||
|
||
ONE_DAY_IN_MS = 24 * 60 * 60 * 1000 | ||
|
@@ -305,6 +305,60 @@ class DownAndKeepDaysPolicy(DownPolicy): | |
pass | ||
|
||
|
||
class CopyPolicy(AbstractFileSyncPolicy): | ||
""" | ||
File is copied (server-side). | ||
""" | ||
DESTINATION_PREFIX = 'b2://' | ||
SOURCE_PREFIX = 'b2://' | ||
|
||
def _make_transfer_action(self): | ||
return B2CopyAction( | ||
self._source_file.name, | ||
self._source_folder.make_full_path(self._source_file.name), | ||
self._source_file.latest_version().id_, | ||
self._dest_folder.make_full_path(self._source_file.name), | ||
self._get_source_mod_time(), | ||
self._source_file.latest_version().size, | ||
) | ||
|
||
|
||
class CopyAndDeletePolicy(CopyPolicy): | ||
""" | ||
File is copied (server-side) and the delete flag is SET. | ||
""" | ||
|
||
def _get_hide_delete_actions(self): | ||
for action in super()._get_hide_delete_actions(): | ||
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. What actions might the parent class have that we want to use here? (It looks like the actual base class just returns the empty list.) 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. If the parent class will start returning something, we'd like this class (and all descendants) to honor that without modification of the inheriting classes |
||
yield action | ||
for action in make_b2_delete_actions( | ||
self._source_file, | ||
self._dest_file, | ||
self._dest_folder, | ||
self._transferred, | ||
): | ||
yield action | ||
|
||
|
||
class CopyAndKeepDaysPolicy(CopyPolicy): | ||
""" | ||
File is copied (server-side) and the keepDays flag is SET. | ||
""" | ||
|
||
def _get_hide_delete_actions(self): | ||
for action in super()._get_hide_delete_actions(): | ||
yield action | ||
for action in make_b2_keep_days_actions( | ||
self._source_file, | ||
self._dest_file, | ||
self._dest_folder, | ||
self._transferred, | ||
self._keep_days, | ||
self._now_millis, | ||
): | ||
yield action | ||
|
||
|
||
def make_b2_delete_note(version, index, transferred): | ||
""" | ||
Create a note message for delete action. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ | |
|
||
class CopySource(OutboundTransferSource): | ||
def __init__(self, file_id, offset=0, length=None): | ||
if length is None and offset > 0: | ||
raise ValueError('Cannot copy with non zero offset and unknown length') | ||
if not length and offset > 0: | ||
raise ValueError('Cannot copy with non zero offset and unknown or zero length') | ||
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. Why? Can't we copy a zero-length file? 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. We could, but we'd rather not. Uploads are A-class transactions (free), but 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 is an emerger code. See my previous comment. |
||
self.file_id = file_id | ||
self.length = length | ||
self.offset = offset | ||
|
@@ -38,13 +38,15 @@ def is_copy(self): | |
return True | ||
|
||
def get_bytes_range(self): | ||
if self.length is None: | ||
if not self.length: | ||
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. here, too 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. Same here |
||
if self.offset > 0: | ||
# auto mode should get file info and create correct copy source (with length) | ||
raise ValueError('cannot return bytes range for non zero offset and unknown length') | ||
raise ValueError( | ||
'cannot return bytes range for non zero offset and unknown or zero length' | ||
) | ||
return None | ||
|
||
return (self.offset, self.offset + self.length - 1) | ||
return self.offset, self.offset + self.length - 1 | ||
|
||
def get_copy_source_range(self, relative_offset, range_length): | ||
if self.length is not None and range_length + relative_offset > self.length: | ||
|
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.
This check is not the same when
length
is 0. I think this first branch should still happen in that case.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.
The first branch is using a simple copy manager and the second emerger created by @mzukowski-reef
The problem is that emerger doesn't work when copying 0-length files and actually is not needed for such files