From 7ae53312187ad036971faeea1fd08d77a89aa67f Mon Sep 17 00:00:00 2001 From: Mohammadreza Abdoli Date: Sat, 18 Jan 2020 01:02:14 +0330 Subject: [PATCH] update ismount() to match upstream from cPython (#64586) --- ...4586-copy-upstream-version-of-ismount.yaml | 2 + lib/ansible/module_utils/ismount.py | 40 +++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 changelogs/fragments/64586-copy-upstream-version-of-ismount.yaml diff --git a/changelogs/fragments/64586-copy-upstream-version-of-ismount.yaml b/changelogs/fragments/64586-copy-upstream-version-of-ismount.yaml new file mode 100644 index 00000000000..e15f9b2746a --- /dev/null +++ b/changelogs/fragments/64586-copy-upstream-version-of-ismount.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ismount - clone upstream version of ismount() (https://github.com/ansible/ansible/issues/63977) \ No newline at end of file diff --git a/lib/ansible/module_utils/ismount.py b/lib/ansible/module_utils/ismount.py index 325a039e8e1..62feb354cc6 100644 --- a/lib/ansible/module_utils/ismount.py +++ b/lib/ansible/module_utils/ismount.py @@ -53,38 +53,38 @@ import os def ismount(path): """Test whether a path is a mount point - clone of os.path.ismount (from cpython Lib/posixpath.py) - fixed to solve https://github.com/ansible/ansible-modules-core/issues/2186 - and workaround non-fixed http://bugs.python.org/issue2466 - this should be rewritten as soon as python issue 2466 is fixed - probably check for python version and use os.path.ismount if fixed - - to remove replace in this file ismount( -> os.path.ismount( and remove this - function""" - + This is a copy of the upstream version of ismount(). Originally this was copied here as a workaround + until Python issue 2466 was fixed. Now it is here so this will work on older versions of Python + that may not have the upstream fix. + https://github.com/ansible/ansible-modules-core/issues/2186 + http://bugs.python.org/issue2466 + """ try: s1 = os.lstat(path) - except OSError: - # the OSError should be handled with more care - # it could be a "permission denied" but path is still a mount + except (OSError, ValueError): + # It doesn't exist -- so not a mount point. :-) return False else: # A symlink can never be a mount point if os.path.stat.S_ISLNK(s1.st_mode): return False - parent = os.path.join(path, os.path.pardir) + if isinstance(path, bytes): + parent = os.path.join(path, b'..') + else: + parent = os.path.join(path, '..') parent = os.path.realpath(parent) - try: s2 = os.lstat(parent) - except OSError: - # one should handle the returned OSError with more care to figure - # out whether this is still a mount + except (OSError, ValueError): return False - if s1.st_dev != s2.st_dev: + dev1 = s1.st_dev + dev2 = s2.st_dev + if dev1 != dev2: return True # path/.. on a different device as path - if s1.st_ino == s2.st_ino: - return True # path/.. is the same i-node as path, i.e. path=='/' + ino1 = s1.st_ino + ino2 = s2.st_ino + if ino1 == ino2: + return True # path/.. is the same i-node as path return False