diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-03-01 16:18:04 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-03-01 16:18:04 +0000 |
commit | 5b28c2a885a2e77578f3c37e3dd534055ba3a3e9 (patch) | |
tree | 9d4db18286514af997433cff5a6d55ac4259d5d1 /morphlib/stagingarea.py | |
parent | c909f89474fbdb3a57e647f2edb81f45ef6a55f3 (diff) | |
download | morph-5b28c2a885a2e77578f3c37e3dd534055ba3a3e9.tar.gz |
Fix existence checks to not follow symlinks
When we hardlink the staging area tree, we were checking if the
target file already exists with os.path.exists. Unfortunately, this
follows a symlink, and in this case, we don't want to: if the
symlink target exists, and is a symlink, we want to remove the symlink
only, and we don't care about its target.
The target file may exists because of overlapping files in chunks.
Reported-By: Paul Sherwood
Diffstat (limited to 'morphlib/stagingarea.py')
-rw-r--r-- | morphlib/stagingarea.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py index f930f9d7..ae9e7e39 100644 --- a/morphlib/stagingarea.py +++ b/morphlib/stagingarea.py @@ -98,7 +98,7 @@ class StagingArea(object): if stat.S_ISDIR(mode): # Ensure directory exists in destination, then recurse. - if not os.path.exists(destpath): + if not os.path.lexists(destpath): os.makedirs(destpath) dest_stat = os.stat(os.path.realpath(destpath)) if not stat.S_ISDIR(dest_stat.st_mode): @@ -110,19 +110,19 @@ class StagingArea(object): os.path.join(destpath, entry)) elif stat.S_ISLNK(mode): # Copy the symlink. - if os.path.exists(destpath): + if os.path.lexists(destpath): os.remove(destpath) os.symlink(os.readlink(srcpath), destpath) elif stat.S_ISREG(mode): # Hardlink the file. - if os.path.exists(destpath): + if os.path.lexists(destpath): os.remove(destpath) os.link(srcpath, destpath) elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode): # Block or character device. Put contents of st_dev in a mknod. - if os.path.exists(destpath): + if os.path.lexists(destpath): os.remove(destpath) os.mknod(destpath, file_stat.st_mode, file_stat.st_rdev) os.chmod(destpath, file_stat.st_mode) |