summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-02-16 15:54:01 +0000
committerLars Wirzenius <liw@liw.fi>2013-02-16 15:54:01 +0000
commitb64418d388610bf86922481226cbbc641d4395db (patch)
tree5698a26a8bdaa49934cce0f441ae99dfb959ac39
parenta70ab9a6c0c1be7e94a9a87229b72a4bea5309b0 (diff)
downloadobnam-b64418d388610bf86922481226cbbc641d4395db.tar.gz
Fix restore of symlinks as root
Reported-By: David Fries
-rw-r--r--NEWS2
-rw-r--r--obnamlib/metadata.py8
2 files changed, 7 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index a1a832fb..073d9c79 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,8 @@ Bug fixes:
needed for fsck to work.
* The manual page did not document the client name arguments to the
`add-key` and `remove-key` subcommands. Reported by Lars Kruse.
+* Restoring symlinks as root would fail. Reported and fixed by
+ David Fries.
Version 1.3, released 2012-12-16
--------------------------------
diff --git a/obnamlib/metadata.py b/obnamlib/metadata.py
index e31bafae..a3c1bea0 100644
--- a/obnamlib/metadata.py
+++ b/obnamlib/metadata.py
@@ -238,14 +238,16 @@ def set_metadata(fs, filename, metadata, getuid=None):
'''
+ symlink = stat.S_ISLNK(metadata.st_mode)
+ if symlink:
+ fs.symlink(metadata.target, filename)
+
# Set owner before mode, so that a setuid bit does not get reset.
getuid = getuid or os.getuid
if getuid() == 0:
fs.lchown(filename, metadata.st_uid, metadata.st_gid)
- if stat.S_ISLNK(metadata.st_mode):
- fs.symlink(metadata.target, filename)
- else:
+ if not symlink:
# If we are not the owner, and not root, do not restore setuid/setgid.
mode = metadata.st_mode
if getuid() not in (0, metadata.st_uid): # pragma: no cover