On Thu, 21 Jun 2012 10:23:25 -0000 "Armin Ronacher" <armin.ronacher at active-4.com> wrote: > Due to an user error on my part I was not using os.readlink correctly. > Since links can be relative to their location I think it would make sense > to provide an os.path.resolve helper that automatically returns the > absolute path: > > def resolve(filename): > try: > target = os.readlink(filename) > except OSError as e: > if e.errno == errno.EINVAL: > return abspath(filename) > raise > return normpath(join(dirname(filename), target)) Note that abspath() is buggy in the face of symlinks, for example it will happily collapse /etc/foo/../bar into /etc/bar, even though /etc/foo might be a link to /usr/lib/foo The only safe way to collapse ".." elements is to resolve symlinks. Regards Antoine.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4