-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
transfer: preserve workspace data #6860
Changes from all commits
f7b70f4
7acb817
7c9dc68
15b1169
ffa7650
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 |
---|---|---|
|
@@ -97,13 +97,13 @@ def _link(cache, from_info, to_info): | |
raise CheckoutError([str(to_info)]) from exc | ||
|
||
|
||
def _cache_is_copy(cache, path_info): | ||
def _confirm_cache_type(cache, path_info): | ||
"""Checks whether cache uses copies.""" | ||
if cache.cache_type_confirmed: | ||
return cache.cache_types[0] == "copy" | ||
return | ||
|
||
if set(cache.cache_types) <= {"copy"}: | ||
return True | ||
return | ||
|
||
workspace_file = path_info.with_name("." + uuid()) | ||
test_cache_file = cache.path_info / ".cache_type_test_file" | ||
|
@@ -118,7 +118,16 @@ def _cache_is_copy(cache, path_info): | |
cache.fs.remove(test_cache_file) | ||
|
||
cache.cache_type_confirmed = True | ||
return cache.cache_types[0] == "copy" | ||
|
||
|
||
def _relink(cache, cache_info, fs, path_info, in_cache, force): | ||
_remove(path_info, fs, in_cache, force=force) | ||
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. Another thing we could do here is move original file aside (e.g. 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.
But here we only create a link and that would not cost too much storage. Even in the worst condition the overall storage cost would only be a little more than before the operation. Btw,
Looks similar to it. |
||
_link(cache, cache_info, path_info) | ||
# NOTE: Depending on a file system (e.g. on NTFS), `_remove` might reset | ||
# read-only permissions in order to delete a hardlink to protected object, | ||
# which will also reset it for the object itself, making it unprotected, | ||
# so we need to protect it back. | ||
cache.protect(cache_info) | ||
|
||
|
||
def _checkout_file( | ||
|
@@ -133,18 +142,33 @@ def _checkout_file( | |
): | ||
"""The file is changed we need to checkout a new copy""" | ||
modified = False | ||
|
||
_confirm_cache_type(cache, path_info) | ||
|
||
cache_info = cache.hash_to_path_info(change.new.oid.value) | ||
if change.old.oid: | ||
if relink: | ||
if fs.iscopy(path_info) and _cache_is_copy(cache, path_info): | ||
if fs.iscopy(path_info) and cache.cache_types[0] == "copy": | ||
cache.unprotect(path_info) | ||
else: | ||
_remove(path_info, fs, change.old.in_cache, force=force) | ||
_link(cache, cache_info, path_info) | ||
_relink( | ||
cache, | ||
cache_info, | ||
fs, | ||
path_info, | ||
change.old.in_cache, | ||
force=force, | ||
) | ||
else: | ||
modified = True | ||
_remove(path_info, fs, change.old.in_cache, force=force) | ||
_link(cache, cache_info, path_info) | ||
_relink( | ||
cache, | ||
cache_info, | ||
fs, | ||
path_info, | ||
change.old.in_cache, | ||
force=force, | ||
) | ||
else: | ||
_link(cache, cache_info, path_info) | ||
modified = True | ||
|
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.
Will unify this with the stuff we do in
checkout
in the followups, since it is out of scope.