Merge "Don't open subdirectories rootwrap filter directories"

This commit is contained in:
Jenkins 2017-03-02 21:58:29 +00:00 committed by Gerrit Code Review
commit a9ad4ec0f9
2 changed files with 5 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class RootwrapLoaderTestCase(testtools.TestCase):
def test_strict_switched_off_in_configparser(self): def test_strict_switched_off_in_configparser(self):
temp_dir = self.useFixture(fixtures.TempDir()).path temp_dir = self.useFixture(fixtures.TempDir()).path
os.mkdir(os.path.join(temp_dir, 'nested'))
temp_file = os.path.join(temp_dir, 'test.conf') temp_file = os.path.join(temp_dir, 'test.conf')
f = open(temp_file, 'w') f = open(temp_file, 'w')
f.write("""[Filters] f.write("""[Filters]

View File

@ -120,9 +120,12 @@ def load_filters(filters_path):
continue continue
for filterfile in filter(lambda f: not f.startswith('.'), for filterfile in filter(lambda f: not f.startswith('.'),
os.listdir(filterdir)): os.listdir(filterdir)):
filterfilepath = os.path.join(filterdir, filterfile)
if not os.path.isfile(filterfilepath):
continue
kwargs = {"strict": False} if six.PY3 else {} kwargs = {"strict": False} if six.PY3 else {}
filterconfig = moves.configparser.RawConfigParser(**kwargs) filterconfig = moves.configparser.RawConfigParser(**kwargs)
filterconfig.read(os.path.join(filterdir, filterfile)) filterconfig.read(filterfilepath)
for (name, value) in filterconfig.items("Filters"): for (name, value) in filterconfig.items("Filters"):
filterdefinition = [s.strip() for s in value.split(',')] filterdefinition = [s.strip() for s in value.split(',')]
newfilter = build_filter(*filterdefinition) newfilter = build_filter(*filterdefinition)