summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/lib/libposixpath.tex7
-rw-r--r--Lib/dospath.py3
-rw-r--r--Lib/macpath.py3
-rw-r--r--Lib/ntpath.py3
-rw-r--r--Lib/plat-riscos/riscospath.py4
-rw-r--r--Lib/posixpath.py21
6 files changed, 41 insertions, 0 deletions
diff --git a/Doc/lib/libposixpath.tex b/Doc/lib/libposixpath.tex
index 658b4ea..9cd1a58 100644
--- a/Doc/lib/libposixpath.tex
+++ b/Doc/lib/libposixpath.tex
@@ -137,6 +137,13 @@ case (use \function{normcase()} for that). On Windows, it converts
forward slashes to backward slashes.
\end{funcdesc}
+\begin{funcdesc}{realpath}{path}
+Return the canonical path of the specified filename, eliminating any
+symbolic links encountered in the path.
+Availability: \UNIX{}.
+\versionadded{2.2}
+\end{funcdesc}
+
\begin{funcdesc}{samefile}{path1, path2}
Return true if both pathname arguments refer to the same file or
directory (as indicated by device number and i-node number).
diff --git a/Lib/dospath.py b/Lib/dospath.py
index 958f9f6..5f60705 100644
--- a/Lib/dospath.py
+++ b/Lib/dospath.py
@@ -330,3 +330,6 @@ def abspath(path):
if not isabs(path):
path = join(os.getcwd(), path)
return normpath(path)
+
+# realpath is a no-op on systems without islink support
+realpath = abspath
diff --git a/Lib/macpath.py b/Lib/macpath.py
index 46ae764..1ef35ef 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -225,3 +225,6 @@ def abspath(path):
if not isabs(path):
path = join(os.getcwd(), path)
return normpath(path)
+
+# realpath is a no-op on systems without islink support
+realpath = abspath
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index d55cc7c..a1baf83 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -451,3 +451,6 @@ def abspath(path):
else:
path = os.getcwd()
return normpath(path)
+
+# realpath is a no-op on systems without islink support
+realpath = abspath
diff --git a/Lib/plat-riscos/riscospath.py b/Lib/plat-riscos/riscospath.py
index 32f39ba..8eda834 100644
--- a/Lib/plat-riscos/riscospath.py
+++ b/Lib/plat-riscos/riscospath.py
@@ -315,6 +315,10 @@ def abspath(p):
return normpath(join(os.getcwd(), p))
+# realpath is a no-op on systems without islink support
+realpath = abspath
+
+
# Normalize a path. Only special path element under RISC OS is "^" for "..".
def normpath(p):
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 6bf40f8..0f6b6a7 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -379,3 +379,24 @@ def abspath(path):
if not isabs(path):
path = join(os.getcwd(), path)
return normpath(path)
+
+
+# Return a canonical path (i.e. the absolute location of a file on the
+# filesystem).
+
+def realpath(filename):
+ """Return the canonical path of the specified filename, eliminating any
+symbolic links encountered in the path."""
+ filename = abspath(filename)
+
+ bits = ['/'] + filename.split('/')[1:]
+ for i in range(2, len(bits)+1):
+ component = join(*bits[0:i])
+ if islink(component):
+ resolved = os.readlink(component)
+ (dir, file) = split(component)
+ resolved = normpath(join(dir, resolved))
+ newpath = join(*([resolved] + bits[i:]))
+ return realpath(newpath)
+
+ return filename