Skip to content

Commit

Permalink
Strip leading/trailing spaces/tabs from mirrors
Browse files Browse the repository at this point in the history
If a Debian mirror has leading/trailing spaces/tabs, mmdebstrap will
fail:

```
I: running apt-get update...
E: Malformed entry 3 in list file /tmpfs/mmdebstrap.IQ6vCUfFh5/etc/apt/sources.list (URI parse)
E: The list of sources could not be read.
E: apt-get update -oAPT::Status-Fd=<$fd> -oDpkg::Use-Pty=false failed
I: main() received signal PIPE: waiting for setup...
W: listening on child socket failed: E: received eof on socket
```

Therefore strip leading/trailing spaces/tabs from the mirrors specified
with `--mirrors`.

Signed-off-by: Benjamin Drung <[email protected]>
  • Loading branch information
bdrung committed Jun 18, 2020
1 parent 49a50f2 commit d15a4e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bdebstrap
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,16 @@ def parse_args(args): # pylint: disable=too-many-statements
args.components = [c for l in args.components for c in re.split(",| ", l) if c]
if args.architectures:
args.architectures = [a for l in args.architectures for a in re.split(",| ", l) if a]
args.mirrors = [m for mirror_list in args.mirrors for m in mirror_list.split(",") if m]
args.mirrors = [
m.strip() for mirror_list in args.mirrors for m in mirror_list.split(",") if m.strip()
]

# Positional arguments override optional arguments (or extent them in case of "mirrors")
if args.suite_positional:
args.suite = args.suite_positional
if args.target_positional:
args.target = args.target_positional
args.mirrors += [m for m in args.mirrors_positional if m]
args.mirrors += [m.strip() for m in args.mirrors_positional if m.strip()]
del args.suite_positional
del args.target_positional
del args.mirrors_positional
Expand Down
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ def test_malformed_env(self):
with self.assertRaises(SystemExit):
parse_args(["--env", "invalid"])

def test_mirrors_with_spaces(self):
"""Test --mirrors with leading/trailing spaces."""
args = parse_args(
[
"--mirrors",
" deb http://deb.debian.org/debian unstable main\t , \t, "
"deb http://deb.debian.org/debian unstable non-free\t",
"--mirrors",
"\tdeb http://deb.debian.org/debian unstable contrib ",
]
)
self.assertDictContainsSubset(
{
"mirrors": [
"deb http://deb.debian.org/debian unstable main",
"deb http://deb.debian.org/debian unstable non-free",
"deb http://deb.debian.org/debian unstable contrib",
],
},
args.__dict__,
)

def test_optional_args(self):
"""Test optional arguments (which also have positional ones)."""
args = parse_args(
Expand Down

0 comments on commit d15a4e1

Please sign in to comment.