Skip to content

Commit

Permalink
CP-53783: use os.path.realpath instead of incorrect internal
Browse files Browse the repository at this point in the history
The implementation in get_real_path does not correctly canonicalize
the resulting path which anyuser of realpath would expect to be the
case. Replace with the python standard library version.

Also remove the unused getThisScript method from cleanup.py which also
used this method.

Signed-off-by: Mark Syms <[email protected]>
  • Loading branch information
MarkSymsCtx committed Mar 3, 2025
1 parent 25ceda3 commit cc5c652
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
7 changes: 0 additions & 7 deletions drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,6 @@ def countBits(bitmap1, bitmap2):
return count
countBits = staticmethod(countBits)

def getThisScript():
thisScript = util.get_real_path(__file__)
if thisScript.endswith(".pyc"):
thisScript = thisScript[:-1]
return thisScript
getThisScript = staticmethod(getThisScript)


################################################################################
#
Expand Down
2 changes: 1 addition & 1 deletion drivers/mpath_dmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _is_valid_multipath_device(sid):
# Some paths might be down, check all associated devices
for dev in devs:
devpath = os.path.join(by_scsid_path, dev)
real_path = util.get_real_path(devpath)
real_path = os.path.realpath(devpath)
with Fairlock("devicemapper"):
(ret, stdout, stderr) = util.doexec(['/usr/sbin/multipath', '-c', real_path])
if ret == 0:
Expand Down
11 changes: 0 additions & 11 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,6 @@ def get_secret(session, uuid):
raise xs_errors.XenError('InvalidSecret', opterr='Unable to look up secret [%s]' % uuid)


def get_real_path(path):
"Follow symlinks to the actual file"
absPath = path
directory = ''
while os.path.islink(absPath):
directory = os.path.dirname(absPath)
absPath = os.readlink(absPath)
absPath = os.path.join(directory, absPath)
return absPath


def wait_for_path(path, timeout):
for i in range(0, timeout):
if len(glob.glob(path)):
Expand Down

0 comments on commit cc5c652

Please sign in to comment.