Skip to content

Commit

Permalink
Added ability to hide directories within the fileserver
Browse files Browse the repository at this point in the history
  • Loading branch information
tf198 committed Dec 22, 2012
1 parent 3756a83 commit 8a30f60
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions salt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ def master_config(path):
'file_buffer_size': 1048576,
'file_ignore_regex': None,
'file_ignore_glob': None,
'path_hide_regex': None,
'path_hide_glob': None,
'max_open_files': 100000,
'hash_type': 'md5',
'conf_file': path,
Expand Down
40 changes: 31 additions & 9 deletions salt/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,25 @@ def __is_file_ignored(self, fn):
return True
return False

def __is_path_hidden(self, fn):
'''
If path_hide_regex or path_hide_glob were given in config,
compare the given path against all of them and return True
on the first match
'''
if self.opts['path_hide_regex']:
for r in self.opts['path_hide_regex']:
if re.search(r, fn):
log.debug('Path matching path_hide_regex. Skipping: {0}'.format(fn))
return True

if self.opts['path_hide_glob']:
for g in self.opts['path_hide_glob']:
if fnmatch.fnmatch(fn, g):
log.debug('Path matching path_hide_glob. Skipping: {0}'.format(fn))
return True
return False

def _ext_nodes(self, load):
'''
Return the results from an external node classifier if one is
Expand Down Expand Up @@ -719,13 +738,14 @@ def _file_list(self, load):

for path in self.opts['file_roots'][load['env']]:
for root, dirs, files in os.walk(path, followlinks=True):
for fn in files:
rel_fn = os.path.relpath(
os.path.join(root, fn),
path
)
if not self.__is_file_ignored(rel_fn):
ret.append(rel_fn)
if not self.__is_path_hidden(os.path.relpath(root, path)):
for fn in files:
rel_fn = os.path.relpath(
os.path.join(root, fn),
path
)
if not self.__is_file_ignored(rel_fn):
ret.append(rel_fn)
return ret

def _file_list_emptydirs(self, load):
Expand All @@ -739,7 +759,7 @@ def _file_list_emptydirs(self, load):
for root, dirs, files in os.walk(path, followlinks=True):
if len(dirs) == 0 and len(files) == 0:
rel_fn = os.path.relpath(root, path)
if not self.__is_file_ignored(rel_fn):
if not self.__is_file_ignored(rel_fn) and not self.__is_path_hidden(rel_fn):
ret.append(rel_fn)
return ret

Expand All @@ -752,7 +772,9 @@ def _dir_list(self, load):
return ret
for path in self.opts['file_roots'][load['env']]:
for root, dirs, files in os.walk(path, followlinks=True):
ret.append(os.path.relpath(root, path))
rel_fn = os.path.relpath(root, path)
if not self.__is_path_hidden(rel_fn):
ret.append(rel_fn)
return ret

def _master_opts(self, load):
Expand Down

0 comments on commit 8a30f60

Please sign in to comment.