[PATCH v2 3/5] fsck: add and begin to use standardized EXIT_* codes

0 views
Skip to first unread message

Rob Browning

unread,
Jun 19, 2024, 3:16:42 PM (14 days ago) Jun 19
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
lib/bup/cmd/fsck.py | 9 ++++-----
lib/bup/helpers.py | 12 +++++++++++-
2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/lib/bup/cmd/fsck.py b/lib/bup/cmd/fsck.py
index f0aac3583..2339fb903 100644
--- a/lib/bup/cmd/fsck.py
+++ b/lib/bup/cmd/fsck.py
@@ -8,7 +8,9 @@ import glob, os, subprocess, sys

from bup import options, git
from bup.compat import argv_bytes
-from bup.helpers import Sha1, chunkyreader, istty2, log, progress, temp_dir
+from bup.helpers \
+ import (EXIT_FALSE, EXIT_TRUE,
+ Sha1, chunkyreader, istty2, log, progress, temp_dir)
from bup.io import byte_stream


@@ -209,10 +211,7 @@ def main(argv):

par2_setup()
if opt.par2_ok:
- if par2_ok:
- sys.exit(0) # 'true' in sh
- else:
- sys.exit(1)
+ sys.exit(EXIT_TRUE if par2_ok else EXIT_FALSE)
if opt.disable_par2:
par2_ok = 0

diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py
index 8c9338432..881e8dffa 100644
--- a/lib/bup/helpers.py
+++ b/lib/bup/helpers.py
@@ -1,6 +1,5 @@
"""Helper functions and classes for bup."""

-from __future__ import absolute_import, division
from collections import namedtuple
from contextlib import ExitStack
from ctypes import sizeof, c_void_p
@@ -21,6 +20,17 @@ from bup.io import byte_stream, path_msg
from bup.options import _tty_width as tty_width


+# EXIT_TRUE (just an alias) and EXIT_FALSE are intended for cases like
+# POSIX grep or test, or bup's own "fsck --par2-ok", where the command
+# is asking a question with a yes or no answer. Eventually all
+# commands should avoid exiting with 1 for errors.
+
+EXIT_SUCCESS = 0
+EXIT_TRUE = 0
+EXIT_FALSE = 1
+EXIT_FAILURE = 2
+
+
buglvl = int(os.environ.get('BUP_DEBUG', 0))


--
2.43.0

Reply all
Reply to author
Forward
0 new messages