Skip to content

Commit

Permalink
Return None when find_file identifies the path as a directory (saltst…
Browse files Browse the repository at this point in the history
…ack#36342)

This fixes a traceback in the LocalClient when you try to use
cp.cache_file on a directory instead of a file.
  • Loading branch information
Erik Johnson authored and Nicole Thomas committed Sep 15, 2016
1 parent dc518c5 commit ef128ad
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@ def find_file(self, path, tgt_env):
path = salt.utils.path_join(os.path.dirname(path), link_tgt)
else:
blob = file_blob
if isinstance(blob, git.Tree):
# Path is a directory, not a file.
blob = None
break
except KeyError:
# File not found or repo_path points to a directory
Expand Down Expand Up @@ -1417,6 +1420,9 @@ def find_file(self, path, tgt_env):
else:
oid = tree[path].oid
blob = self.repo[oid]
if isinstance(blob, pygit2.Tree):
# Path is a directory, not a file.
blob = None
break
except KeyError:
blob = None
Expand Down Expand Up @@ -1792,6 +1798,9 @@ def find_file(self, path, tgt_env):
path = salt.utils.path_join(os.path.dirname(path), link_tgt)
else:
blob = self.repo.get_object(oid)
if isinstance(blob, dulwich.objects.Tree):
# Path is a directory, not a file.
blob = None
break
except KeyError:
blob = None
Expand Down

0 comments on commit ef128ad

Please sign in to comment.