Fix for seemingly random filename ordering when running through a directory of configuration files (#157).

This commit is contained in:
Dan Helfman 2019-03-30 16:41:21 -07:00
parent 576377e2b2
commit 0b59c22c23
4 changed files with 16 additions and 4 deletions

4
NEWS
View file

@ -1,3 +1,7 @@
1.3.1.dev0
* #157: Fix for seemingly random filename ordering when running through a directory of
configuration files.
1.3.0 1.3.0
* #148: Configuration file includes and merging via "!include" tag to support reuse of common * #148: Configuration file includes and merging via "!include" tag to support reuse of common
options across configuration files. options across configuration files.

View file

@ -41,7 +41,7 @@ def collect_config_filenames(config_paths):
yield path yield path
continue continue
for filename in os.listdir(path): for filename in sorted(os.listdir(path)):
full_filename = os.path.join(path, filename) full_filename = os.path.join(path, filename)
if full_filename.endswith('.yaml') and not os.path.isdir(full_filename): if full_filename.endswith('.yaml') and not os.path.isdir(full_filename):
yield full_filename yield full_filename

View file

@ -1,7 +1,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
VERSION = '1.3.0' VERSION = '1.3.1.dev0'
setup( setup(

View file

@ -1,3 +1,5 @@
import sys
from flexmock import flexmock from flexmock import flexmock
from borgmatic.config import collect as module from borgmatic.config import collect as module
@ -37,7 +39,10 @@ def test_collect_config_filenames_collects_files_from_given_directories_and_igno
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False) mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar').and_return(True) mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar').and_return(True)
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.yaml').and_return(False) mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.yaml').and_return(False)
flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar', 'baz.yaml']) flexmock(module.os).should_receive('listdir')
flexmock(sys.modules['builtins']).should_receive('sorted').and_return(
['foo.yaml', 'bar', 'baz.yaml']
)
config_filenames = tuple(module.collect_config_filenames(config_paths)) config_filenames = tuple(module.collect_config_filenames(config_paths))
@ -56,7 +61,10 @@ def test_collect_config_filenames_collects_files_from_given_directories_and_igno
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False) mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar.yaml~').and_return(False) mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar.yaml~').and_return(False)
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.txt').and_return(False) mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.txt').and_return(False)
flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar.yaml~', 'baz.txt']) flexmock(module.os).should_receive('listdir')
flexmock(sys.modules['builtins']).should_receive('sorted').and_return(
['foo.yaml', 'bar.yaml~', 'baz.txt']
)
config_filenames = tuple(module.collect_config_filenames(config_paths)) config_filenames = tuple(module.collect_config_filenames(config_paths))