Explorar o código

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

Dan Helfman %!s(int64=6) %!d(string=hai) anos
pai
achega
0b59c22c23
Modificáronse 4 ficheiros con 16 adicións e 4 borrados
  1. 4 0
      NEWS
  2. 1 1
      borgmatic/config/collect.py
  3. 1 1
      setup.py
  4. 10 2
      tests/unit/config/test_collect.py

+ 4 - 0
NEWS

@@ -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
  * #148: Configuration file includes and merging via "!include" tag to support reuse of common
    options across configuration files.

+ 1 - 1
borgmatic/config/collect.py

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

+ 1 - 1
setup.py

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

+ 10 - 2
tests/unit/config/test_collect.py

@@ -1,3 +1,5 @@
+import sys
+
 from flexmock import flexmock
 
 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/bar').and_return(True)
     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))
 
@@ -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/bar.yaml~').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))