use default_notty=False for confirmations, fixes #345

this is so that e.g. cron jobs do not hang indefinitely if yes() is called,
but it will just default to "no" if not tty is connected.

if you need to enforce a "yes" answer (which is not recommended for
the security critical questions), you can use the environment:

BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=Y
This commit is contained in:
Thomas Waldmann 2015-11-02 01:59:22 +01:00
parent e6231896cd
commit 36cc377329
2 changed files with 4 additions and 4 deletions

View File

@ -91,7 +91,7 @@ class Archiver:
msg = ("'check --repair' is an experimental feature that might result in data loss." + msg = ("'check --repair' is an experimental feature that might result in data loss." +
"\n" + "\n" +
"Type 'YES' if you understand this and want to continue: ") "Type 'YES' if you understand this and want to continue: ")
if not yes(msg, false_msg="Aborting.", if not yes(msg, false_msg="Aborting.", default_notty=False,
env_var_override='BORG_CHECK_I_KNOW_WHAT_I_AM_DOING', truish=('YES', )): env_var_override='BORG_CHECK_I_KNOW_WHAT_I_AM_DOING', truish=('YES', )):
return EXIT_ERROR return EXIT_ERROR
if not args.archives_only: if not args.archives_only:
@ -335,7 +335,7 @@ class Archiver:
msg.append(format_archive(archive_info)) msg.append(format_archive(archive_info))
msg.append("Type 'YES' if you understand this and want to continue: ") msg.append("Type 'YES' if you understand this and want to continue: ")
msg = '\n'.join(msg) msg = '\n'.join(msg)
if not yes(msg, false_msg="Aborting.", if not yes(msg, false_msg="Aborting.", default_notty=False,
env_var_override='BORG_CHECK_I_KNOW_WHAT_I_AM_DOING', truish=('YES', )): env_var_override='BORG_CHECK_I_KNOW_WHAT_I_AM_DOING', truish=('YES', )):
self.exit_code = EXIT_ERROR self.exit_code = EXIT_ERROR
return self.exit_code return self.exit_code

View File

@ -54,7 +54,7 @@ class Cache:
msg = ("Warning: Attempting to access a previously unknown unencrypted repository!" + msg = ("Warning: Attempting to access a previously unknown unencrypted repository!" +
"\n" + "\n" +
"Do you want to continue? [yN] ") "Do you want to continue? [yN] ")
if not yes(msg, false_msg="Aborting.", if not yes(msg, false_msg="Aborting.", default_notty=False,
env_var_override='BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK'): env_var_override='BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK'):
raise self.CacheInitAbortedError() raise self.CacheInitAbortedError()
self.create() self.create()
@ -64,7 +64,7 @@ class Cache:
msg = ("Warning: The repository at location {} was previously located at {}".format(repository._location.canonical_path(), self.previous_location) + msg = ("Warning: The repository at location {} was previously located at {}".format(repository._location.canonical_path(), self.previous_location) +
"\n" + "\n" +
"Do you want to continue? [yN] ") "Do you want to continue? [yN] ")
if not yes(msg, false_msg="Aborting.", if not yes(msg, false_msg="Aborting.", default_notty=False,
env_var_override='BORG_RELOCATED_REPO_ACCESS_IS_OK'): env_var_override='BORG_RELOCATED_REPO_ACCESS_IS_OK'):
raise self.RepositoryAccessAborted() raise self.RepositoryAccessAborted()