Normalize target paths of symbolic links.

BUG:FIXED:10976
This commit is contained in:
Fatih Aşıcı
2009-08-23 03:43:36 +00:00
parent d269debdec
commit cfb43d7d51
2 changed files with 12 additions and 2 deletions
+3
View File
@@ -1,3 +1,6 @@
2009-08-23 Fatih Aşıcı <fatih@pardus.org.tr>
* Normalize target paths of symbolic links. Fixes #10976.
2009-08-22 Fatih Aşıcı <fatih@pardus.org.tr>
* Add optional destDir parameter to pisitools.dohtml as
pisitools.dodoc supports.
+9 -2
View File
@@ -283,7 +283,7 @@ def dir_size(dir):
return os.path.getsize(dir)
if os.path.islink(dir):
return long(len(os.readlink(dir)))
return long(len(read_link(dir)))
def sizes():
for root, dirs, files in os.walk(dir):
@@ -302,6 +302,13 @@ def copy_file_stat(src,dest):
check_dir(os.path.dirname(dest))
shutil.copy2(src, dest)
def read_link(link):
"""Return the normalized path which is pointed by the symbolic link."""
# tarfile module normalizes the paths pointed by symbolic links. This
# causes problems as the file hashes and sizes are calculated before
# this normalization.
return os.path.normpath(os.readlink(link))
def is_ar_file(file_path):
return open(file_path).read(8) == '!<arch>\n'
@@ -322,7 +329,7 @@ def calculate_hash(path):
"""Return a (path, hash) tuple for given path."""
if os.path.islink(path):
# For symlinks, path string is hashed instead of the content
value = sha1_data(os.readlink(path))
value = sha1_data(read_link(path))
if not os.path.exists(path):
ctx.ui.info(_("Including external link '%s'") % path)
elif os.path.isdir(path):