-
Notifications
You must be signed in to change notification settings - Fork 110
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
ENH: safe-guard --existing-replace for cases of populated directories #4147
ENH: safe-guard --existing-replace for cases of populated directories #4147
Conversation
@@ -287,6 +302,21 @@ def _create_dataset_sibling( | |||
return remoteds_path | |||
|
|||
|
|||
def _ls_remote_path(ssh, path): | |||
try: | |||
# yoh tried ls on mac |
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.
and a dd-wrt router -- both had ls -a1
@@ -287,6 +302,21 @@ def _create_dataset_sibling( | |||
return remoteds_path | |||
|
|||
|
|||
def _ls_remote_path(ssh, 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.
candidate for commands abstractions: https://github.com/datalad/datalad/pull/4068/files#r379009046
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.
True. Will integrate (I'm on it anyway)
def _ls_remote_path(ssh, path): | ||
try: | ||
# yoh tried ls on mac | ||
out, err = ssh("ls -a1 {}".format(sh_quote(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.
Why not just -A1
, eliminating the need to filter out .
and ..
ourselves?
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.
good idea! will do
@@ -163,6 +157,27 @@ def _create_dataset_sibling( | |||
lgr.info(_msg + " Skipping") | |||
return | |||
elif existing == 'replace': | |||
if path_children: | |||
has_git = '.git' in path_children | |||
_msg_stats = _msg \ |
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'd prefer a message that states the actual path it is about to remove rather than calling it "it". Particularly with urls (including replacements insteadOf
) it might not be clear what's the thing we resolved it to.
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 it, but then realized -- path is provided within _msg
, so no need to duplicate, thus "It" is to stay ;)
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.
Ah, true. Sorry.
Codecov Report
@@ Coverage Diff @@
## master #4147 +/- ##
==========================================
- Coverage 89.54% 89.53% -0.01%
==========================================
Files 276 276
Lines 36467 36509 +42
==========================================
+ Hits 32654 32689 +35
- Misses 3813 3820 +7
Continue to review full report at Codecov.
|
ok, pushed c55d702 where I extend doc for This option is indeed as dangerous as $> mkdir -p dir; touch dir/{1,2,3}; rm dir/*
zsh: sure you want to delete all 3 files in /tmp/dir [yn]? y
$> zsh -c 'mkdir -p dir; touch dir/{1,2,3}; rm dir/*'
$> Given that so far nobody shot themselves in the foot, dangers would be properly documented/described, $HOME removal so far has not happened I think this should suffice, and breeding double-force option would not really provide an additional safety blanket. Once again -- the |
b522742
to
a13963d
Compare
…f there was err output
…tion to warning in non-interactive mode
Decision is based on the files listing
a13963d
to
25d4f41
Compare
Pushed a fix and a test for interactive mode. AFAIK this is a viable candidate for the merge. |
@mih, this PR awaits your feedback. |
+ " It is %sa git repository and has %d files/dirs." % ( | ||
"" if has_git else "not ", len(path_children) | ||
) | ||
from datalad.ui import ui |
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.
It's fine to leave this delayed import, but it doesn't actually help in this case:
#!/bin/sh
python <<\EOF | grep datalad | grep ui
import sys
import datalad.distribution.create_sibling
for k in sorted(sys.modules.keys()):
print(k)
EOF
datalad.ui
datalad.ui.base
datalad.ui.dialog
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.
ok, will move up
default=False | ||
) | ||
else: | ||
remove = 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.
Hmm, this is my main concern with this PR. To me it seems like it'd be better to just make the replace-functionality interactive-only.
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.
ok, will do. better be safe than sorry they say ;-)
Apparently was not touched in a big sweep
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.
Thanks for the updates.
Cool! Works for me, thx! |
A safe guard to Close #4145
If remote directory contains some files/directories, we would ask user whenever session is interactive or just raise an exception if not interactive
edit 1: I have been thinking about it and I maintain the opinion that
--existing=replace
is already an explicit indication from the user of the intent to replace (remove, recreate) a possibly existing remote dataset. Adding the interactive question or raising an exception (if not interactive) goes against the explicitly expressed desire to "replace". So, what if we do that (question or exception) only if remote location does not already have.git
and.datalad/config
? This way we would safe guard against some possible erroneous invocations, but would allow for automated (no interaction) and explicitly specified behavior.TODOs (if agreed that it is the way to go)