Skip to content

custom_servers has garbage value on empty config #3497

@Omrifo4

Description

@Omrifo4

Which ISO version are you using?

"2024-12-01"

The installation log

I don't have one, noticed it by reading the code.

describe the problem

What's Wrong?

While parsing the pacman configuration in the installer (lib/installer.py) custom servers config is handled as follows:

# lib/installer.py, lines 540:545

custom_servers = mirror_config.custom_servers_config()
if custom_servers:
    debug(f"Custom servers:\n{custom_servers}")

    content = mirrorlist_config.read_text()
    mirrorlist_config.write_text(f"{custom_servers}\n\n{content}")

Note what happens inside mirror_config.custom_servers_config(), at lib/models/mirrors.py:

# lib/models/mirrors.py, lines 260-266
def custom_servers_config(self) -> str:
    config = "## Custom Servers\n"

    for server in self.custom_servers:
        config += f"Server = {server.url}\n"

    return config.strip()

The Possible Crash

Let's look again on the first code block above:

# lib/installer.py, lines 540:545

# empty config, so `custom_servers = "## Custom Servers\n"`
custom_servers = mirror_config.custom_servers_config()
if custom_servers:
    debug(f"Custom servers:\n{custom_servers}")

    # This will crash if there is no `mirrorlist_config` file!
    content = mirrorlist_config.read_text()
    mirrorlist_config.write_text(f"{custom_servers}\n\n{content}")

custom_servers will hold the (garbage) value ## Custom Servers\n, so we will enter the if clause.

If, for some reason, there is no mirrorlist_config file, the mirrorlist_config.read_text() will crash due to No such file or directory.

The solution is not generating this garbage value on an empty custom_servers config. I will post a fix right away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions