fixed bug in previous commit

Added function to get glob as sorted list. This fixes the errors
reported by systemd-networkd
This commit is contained in:
Pranav Jerry 2021-09-27 11:03:27 +05:30
parent a81449b898
commit 798cd3e988
No known key found for this signature in database
GPG Key ID: F1DCDC4FED0A0C5B
2 changed files with 18 additions and 5 deletions

View File

@ -35,4 +35,4 @@ See README.md for documentation.
#
# In case you forgot to change the version, skip the number
# and put the next number in the next commit.
__version__ = "0.4.0a4"
__version__ = "0.4.0a5"

View File

@ -40,6 +40,20 @@ from naxalnet.daemon import Daemon
from naxalnet.network import NetworkD
def get_sorted_glob(directory: str, glob: str):
"""return sorted list of filenames matching glob"""
path = Path(directory)
g = path.glob(glob)
sorted_list = []
for i in g:
# g is a list of PosixPath objects.
# So we add their absolute path as str.
sorted_list.append(str(i))
# sorted_list is not sorted, so we sort them here
sorted_list.sort()
return sorted_list
def setup_mesh():
"""configure networkd to setup the mesh"""
try:
@ -52,10 +66,9 @@ def setup_mesh():
networkd = NetworkD(runtime_dir=args.networkd_runtime_dir)
# TODO: replace with valus from args
networkd.set_vars(batdev="bat0", bridgedev="bridge0")
for i in Path(args.networkd_config_dir).glob(MESH_GLOB):
path = str(i)
logger.debug("Adding network config %s", path)
networkd.add_config(path)
for i in get_sorted_glob(args.networkd_config_dir, MESH_GLOB):
logger.debug("Adding network config %s", i)
networkd.add_config(i)
except PermissionError:
logger.exception("A PermissionError occured while copying files")
logger.error(REPORT_BUG_INFO)