On 2023-08-29 11:20, Bruno Haible wrote:
People say that "chown only works for root anyway" [1]

I don't think that is the issue here. fchownat is failing with EACCES, which is supposed to mean that search permission is denied on a component of the path prefix, but in Android I guess EACCES also means the calling process doesn't have the required permissions to change ownership (i.e., errno should be EPERM according to POSIX).

Clearly search permission is allowed, since there's a successful utimensat call with the same file name. So EACCES does not mean search permission is denied; it means something else.

Do fchown, chown, and lchown have similar bugs on Android?

Although the attached hacky coreutils patch (which I haven't installed) might solve the immediate problem, it sounds like this is something that Gnulib's fchownat (and maybe related modules) should fix on Android, so that the fix is everywhere and not just in mv+cp.

diff --git a/src/copy.c b/src/copy.c
index b9fff03a3..7b901ffc3 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -3460,6 +3460,12 @@ chown_failure_ok (struct cp_options const *x)
      But root probably wants to know, e.g. if NFS disallows it,
      or if the target system doesn't support file ownership.  */
 
+#ifdef __ANDROID__
+  /* Work around Android bug <https://bugs.gnu.org/65599>.  */
+  if (errno == EACCES && !x->chown_privileges)
+    return true;
+#endif
+
   return ((errno == EPERM || errno == EINVAL) && !x->chown_privileges);
 }
 

Reply via email to