]> arthur.barton.de Git - bup.git/commitdiff
Remove lib.sh actually-root in favor of t/root-status.
authorRob Browning <rlb@defaultvalue.org>
Sun, 26 May 2013 17:16:40 +0000 (12:16 -0500)
committerRob Browning <rlb@defaultvalue.org>
Mon, 27 May 2013 17:28:51 +0000 (12:28 -0500)
Create a t/root-status command that outputs root, fake, or none and
that uses the same cross-platform logic as helpers.py is_superuser().
Use it everywhere.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
t/lib.sh
t/root-status [new file with mode: 0755]
t/test-index-check-device.sh
t/test-meta.sh

index 5696c61ed4b9b58170d9a5dfaa13594371e3d7dc..a683bc3b19c1d450ece8ec8ea30469dc81dc86ec 100644 (file)
--- a/t/lib.sh
+++ b/t/lib.sh
@@ -1,10 +1,5 @@
 # Assumes shell is Bash.
 
-actually-root()
-{
-    test "$(whoami)" == root -a -z "$FAKEROOTKEY"
-}
-
 force-delete()
 {
     # Try *hard* to delete $@.  Among other things, some systems have
diff --git a/t/root-status b/t/root-status
new file mode 100755 (executable)
index 0000000..9fb12cb
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+import sys
+
+if sys.platform.startswith('cygwin'):
+    import ctypes
+    if ctypes.cdll.shell32.IsUserAnAdmin():
+        print 'root'
+    else:
+        print 'none'
+else:
+    import os
+    if os.environ.get('FAKEROOTKEY'):
+        print 'fake'
+    else:
+        if os.geteuid() == 0:
+            print 'root'
+        else:
+            print 'none'
index de7f7ed1d6542968d388aa0f27d5b2c5e341a686..2484fd0bd1495db8f7dc2acd51cccbc8dae9e8c0 100755 (executable)
@@ -4,7 +4,7 @@
 
 set -ex -o pipefail
 
-if ! actually-root; then
+if t/root-status != root; then
     echo 'Not root: skipping --check-device tests.'
     exit 0 # FIXME: add WVSKIP.
 fi
index 29c182813a35d38bb8b28a29c7faab6210c9b881..964a50fd0a54bd60900f144793707e868b94c642 100755 (executable)
@@ -82,7 +82,7 @@ test-src-save-restore()
 
 universal-cleanup()
 {
-    if ! actually-root; then return 0; fi
+    if t/root-status != root; then return 0; fi
     cd "$TOP"
     umount "$TOP/bupmeta.tmp/testfs" || true
     umount "$TOP/bupmeta.tmp/testfs-limited" || true
@@ -374,7 +374,7 @@ WVSTART 'meta --edit'
 
 # Test ownership restoration (when not root or fakeroot).
 (
-    if test "$(whoami)" == root; then
+    if t/root-status != none; then
         exit 0
     fi
 
@@ -440,7 +440,7 @@ WVSTART 'meta --edit'
 
 # Test ownership restoration (when root or fakeroot).
 (
-    if test "$(whoami)" != root; then
+    if t/root-status == none; then
         exit 0
     fi
 
@@ -529,7 +529,7 @@ WVSTART 'meta --edit'
 
 # Root-only tests that require an FS with all the trimmings: ACLs,
 # Linux attr, Linux xattr, etc.
-if actually-root; then
+if t/root-status == root; then
     (
         set -e
         # Some cleanup handled in universal-cleanup() above.