From ef128ad0b0b02b8de91db4274564ee039f6a1ede Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Thu, 15 Sep 2016 15:39:46 -0500 Subject: [PATCH] Return None when find_file identifies the path as a directory (#36342) This fixes a traceback in the LocalClient when you try to use cp.cache_file on a directory instead of a file. --- salt/utils/gitfs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/salt/utils/gitfs.py b/salt/utils/gitfs.py index cefd3d964dda..112e971c49ba 100644 --- a/salt/utils/gitfs.py +++ b/salt/utils/gitfs.py @@ -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 @@ -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 @@ -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