It turns out some Android devices have an empty /etc/passwd and/or
/etc/group, which was defeating the previous workaround. Switch to
testing the intention more directly: we'll try the file in /etc, and if
that didn't work, we'll assume we need a workaround.
---
 tests/chgrp.test | 11 ++++-------
 tests/chown.test | 17 +++++++----------
 2 files changed, 11 insertions(+), 17 deletions(-)
From a828da4a26588f3ca658e3bbb19329623e47c40f Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Wed, 24 Jul 2019 14:52:28 -0700
Subject: [PATCH] tests: fix for empty /etc/passwd or /etc/group.

It turns out some Android devices have an empty /etc/passwd and/or
/etc/group, which was defeating the previous workaround. Switch to
testing the intention more directly: we'll try the file in /etc, and if
that didn't work, we'll assume we need a workaround.
---
 tests/chgrp.test | 11 ++++-------
 tests/chown.test | 17 +++++++----------
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/tests/chgrp.test b/tests/chgrp.test
index 5c7e4258..a137baed 100755
--- a/tests/chgrp.test
+++ b/tests/chgrp.test
@@ -9,13 +9,10 @@ then
   exit
 fi
 
-if [ -f /etc/group ]; then
-  # We chgrp between "root" and the last group in /etc/group.
-  GRP="$(sed -n '$s/:.*//p' /etc/group)"
-else
-  # Or assume we're on Android and pick a well-known group.
-  GRP=shell
-fi
+# We chgrp between "root" and the last group in /etc/group.
+GRP="$(sed -n '$s/:.*//p' /etc/group)"
+# Or if that fails, assume we're on Android and pick a well-known group.
+: "${GRP:=shell}"
 
 # Set up a little testing hierarchy
 
diff --git a/tests/chown.test b/tests/chown.test
index 20be541a..f79d5c1a 100755
--- a/tests/chown.test
+++ b/tests/chown.test
@@ -9,16 +9,13 @@ then
   exit
 fi
 
-if [ -f /etc/group ]; then
-  # We chown between user "root" and the last user in /etc/passwd,
-  # and group "root" and the last group in /etc/group.
-  USR="$(sed -n '$s/:.*//p' /etc/passwd)"
-  GRP="$(sed -n '$s/:.*//p' /etc/group)"
-else
-  # Or we assume we're on Android...
-  USR="shell"
-  GRP="daemon"
-fi
+# We chown between user "root" and the last user in /etc/passwd,
+# and group "root" and the last group in /etc/group.
+USR="$(sed -n '$s/:.*//p' /etc/passwd)"
+GRP="$(sed -n '$s/:.*//p' /etc/group)"
+# Or if that fails, we assume we're on Android...
+: "${USR:=shell}"
+: "${GRP:=daemon}"
 
 # Set up a little testing hierarchy
 
-- 
2.22.0.657.g960e92d24f-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to