Skip to content

Commit 5b9b450

Browse files
add octal_int validator
1 parent 98e2b1d commit 5b9b450

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/borg/archiver/_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..cache import Cache, assert_secure
99
from ..helpers import Error
1010
from ..helpers import SortBySpec, positive_int_validator, location_validator, Location, relative_time_marker_validator
11-
from ..helpers import Highlander
11+
from ..helpers import Highlander, octal_int
1212
from ..helpers.argparsing import SUPPRESS
1313
from ..helpers.nanorst import rst_to_terminal
1414
from ..manifest import Manifest, AI_HUMAN_SORT_KEYS
@@ -510,7 +510,7 @@ def define_common_options(add_common_option):
510510
"--umask",
511511
metavar="M",
512512
dest="umask",
513-
type=lambda s: s if isinstance(s, int) else int(s, 8),
513+
type=octal_int,
514514
default=UMASK_DEFAULT,
515515
action=Highlander,
516516
help="set umask to M (local only, default: %(default)04o)",

src/borg/archiver/create_cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..cache import Cache
1717
from ..constants import * # NOQA
1818
from ..helpers import comment_validator, ChunkerParams, FilesystemPathSpec, CompressionSpec
19-
from ..helpers import archivename_validator, FilesCacheMode
19+
from ..helpers import archivename_validator, FilesCacheMode, octal_int
2020
from ..helpers import eval_escapes
2121
from ..helpers import timestamp, archive_ts_now
2222
from ..helpers import get_cache_dir, os_stat, get_strip_prefix, slashify
@@ -829,7 +829,7 @@ def build_parser_create(self, subparsers, common_parser, mid_common_parser):
829829
"--stdin-mode",
830830
metavar="M",
831831
dest="stdin_mode",
832-
type=lambda s: s if isinstance(s, int) else int(s, 8),
832+
type=octal_int,
833833
default=STDIN_MODE_DEFAULT,
834834
action=Highlander,
835835
help="set mode to M in archive for stdin data (default: %(default)04o)",

src/borg/helpers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .fs import HardLinkManager
2626
from .misc import sysinfo, log_multi, consume
2727
from .misc import ChunkIteratorFileWrapper, open_item, chunkit, iter_separated, ErrorIgnoringTextIOWrapper
28-
from .parseformat import bin_to_hex, hex_to_bin, safe_encode, safe_decode
28+
from .parseformat import octal_int, bin_to_hex, hex_to_bin, safe_encode, safe_decode
2929
from .parseformat import text_to_json, binary_to_json, remove_surrogates, join_cmd
3030
from .parseformat import eval_escapes, decode_dict, positive_int_validator, interval
3131
from .parseformat import (

src/borg/helpers/parseformat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
from ..item import ItemDiff
3636

3737

38+
def octal_int(s):
39+
if isinstance(s, int):
40+
return s
41+
return int(s, 8)
42+
43+
3844
def bin_to_hex(binary):
3945
return binascii.hexlify(binary).decode("ascii")
4046

0 commit comments

Comments
 (0)