mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
networkinterfaces: support relative paths in source/source-directory statements
According to interfaces(5) [1]: When sourcing files or directories, if a path doesn't have a leading slash, it's considered relative to the directory containing the file in which the keyword is placed. In the example above, if the file is located at /etc/network/interfaces, paths to the included files are understood to be under /etc/network. Adapt the implementation to adhere to the documented behaviour. [1] https://manpages.debian.org/buster/ifupdown/interfaces.5.en.html
This commit is contained in:
@@ -161,9 +161,13 @@ class networkInterfaces():
|
||||
|
||||
def process_source(self, lines, cur_idx, lineno):
|
||||
# Support regex
|
||||
self.logger.debug('processing sourced line ..\'%s\'' %lines[cur_idx])
|
||||
self.logger.debug('processing sourced line ..\'%s\'' % lines[cur_idx])
|
||||
sourced_file = re.split(self._ws_split_regex, lines[cur_idx], 2)[1]
|
||||
|
||||
if sourced_file:
|
||||
if not os.path.isabs(sourced_file):
|
||||
sourced_file = os.path.join(os.path.dirname(self._currentfile), sourced_file)
|
||||
|
||||
filenames = sorted(glob.glob(sourced_file))
|
||||
if not filenames:
|
||||
if '*' not in sourced_file:
|
||||
@@ -180,7 +184,11 @@ class networkInterfaces():
|
||||
def process_source_directory(self, lines, cur_idx, lineno):
|
||||
self.logger.debug('processing source-directory line ..\'%s\'' % lines[cur_idx])
|
||||
sourced_directory = re.split(self._ws_split_regex, lines[cur_idx], 2)[1]
|
||||
|
||||
if sourced_directory:
|
||||
if not os.path.isabs(sourced_directory):
|
||||
sourced_directory = os.path.join(os.path.dirname(self._currentfile), sourced_directory)
|
||||
|
||||
folders = glob.glob(sourced_directory)
|
||||
for folder in folders:
|
||||
filenames = [file for file in os.listdir(folder) if re.match(r'^[a-zA-Z0-9_-]+$', file)]
|
||||
|
Reference in New Issue
Block a user