This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: skip tests that raise PermissionError in test_tarfile (non-root user on Android)
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: lars.gustaebel, serhiy.storchaka, xdegaye
Priority: normal Keywords: patch

Created on 2017-01-06 16:31 by xdegaye, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_tarfile.patch xdegaye, 2017-01-07 20:41 review
issue29181_01.patch xdegaye, 2017-01-09 19:39 review
Pull Requests
URL Status Linked Edit
PR 4375 merged xdegaye, 2017-11-11 19:36
Messages (6)
msg284832 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-01-06 16:31
======================================================================                    [339/2616]
ERROR: test_link_size (test.test_tarfile.Bz2WriteTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_tarfile.py", line 1102, in test_link_siz
e
    os.link(target, link)
PermissionError: [Errno 13] Permission denied: '/data/local/tmp/test_python_2295/@test_2295_tmp-tard
ir/link_target' -> '/data/local/tmp/test_python_2295/@test_2295_tmp-tardir/link'

======================================================================
ERROR: test_link_size (test.test_tarfile.GzipWriteTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_tarfile.py", line 1102, in test_link_siz
e
    os.link(target, link)
PermissionError: [Errno 13] Permission denied: '/data/local/tmp/test_python_2295/@test_2295_tmp-tard
ir/link_target' -> '/data/local/tmp/test_python_2295/@test_2295_tmp-tardir/link'

======================================================================
ERROR: test_add_hardlink (test.test_tarfile.HardlinkTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_tarfile.py", line 1563, in setUp
    os.link(self.foo, self.bar)
PermissionError: [Errno 13] Permission denied: '/data/local/tmp/test_python_2295/@test_2295_tmp-tard
ir/foo' -> '/data/local/tmp/test_python_2295/@test_2295_tmp-tardir/bar'

======================================================================
ERROR: test_add_twice (test.test_tarfile.HardlinkTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_tarfile.py", line 1563, in setUp
    os.link(self.foo, self.bar)
PermissionError: [Errno 13] Permission denied: '/data/local/tmp/test_python_2295/@test_2295_tmp-tard
ir/foo' -> '/data/local/tmp/test_python_2295/@test_2295_tmp-tardir/bar'

======================================================================
ERROR: test_dereference_hardlink (test.test_tarfile.HardlinkTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_tarfile.py", line 1563, in setUp
    os.link(self.foo, self.bar)
PermissionError: [Errno 13] Permission denied: '/data/local/tmp/test_python_2295/@test_2295_tmp-tard
ir/foo' -> '/data/local/tmp/test_python_2295/@test_2295_tmp-tardir/bar'

======================================================================
ERROR: test_link_size (test.test_tarfile.WriteTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_tarfile.py", line 1102, in test_link_siz
e
    os.link(target, link)
PermissionError: [Errno 13] Permission denied: '/data/local/tmp/test_python_2295/@test_2295_tmp-tard
ir/link_target' -> '/data/local/tmp/test_python_2295/@test_2295_tmp-tardir/link'

----------------------------------------------------------------------
Ran 426 tests in 17.296s

FAILED (errors=6, skipped=80)
test test_tarfile failed
msg284931 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-01-07 20:41
Patch attached.
msg284935 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-07 21:04
Why os.link() is failed? If hard links are not supported on Android, shouldn't os.link be not implemented? tarfile try to make a copy of the referenced file instead of a link if a link can't be created.
msg284938 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-01-07 21:41
> Why os.link() is failed? If hard links are not supported on Android, shouldn't os.link be not implemented?

Android has a restrictive security model based on SELinux [1].

With the Android adb shell on the emulator at API level 24:

$ >foo
$ ln foo bar
ln: cannot create hard link from 'foo' to 'bar': Permission denied
$ su
# ln foo bar
# ls -li foo bar
15688 -rw-rw-rw- 2 shell shell 0 2017-01-07 22:29 bar
15688 -rw-rw-rw- 2 shell shell 0 2017-01-07 22:29 foo

Here is the Android commit message that does not grant hard link capabilities by default:
https://android.googlesource.com/platform/external/sepolicy/+/85ce2c7

[1] https://source.android.com/security/selinux/
msg285066 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-01-09 19:39
New patch following Serhiy's suggestion in msg285008.
msg306124 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-11-12 17:02
New changeset d7d4fea4a39da4bfdea1de22fe040023eb4ddc17 by xdegaye in branch 'master':
bpo-29181: Skip test_tarfile tests on PermissionError raised by Android (GH-4375)
https://github.com/python/cpython/commit/d7d4fea4a39da4bfdea1de22fe040023eb4ddc17
History
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73367
2017-11-12 17:03:40xdegayesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-11-12 17:02:08xdegayesetmessages: + msg306124
2017-11-11 19:36:32xdegayesetpull_requests: + pull_request4324
2017-11-11 18:43:45xdegayesetversions: - Python 3.6
2017-02-03 18:44:25xdegayesetassignee: xdegaye ->
2017-01-09 19:39:50xdegayesetfiles: + issue29181_01.patch

messages: + msg285066
2017-01-07 21:41:22xdegayesetmessages: + msg284938
2017-01-07 21:04:25serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg284935
2017-01-07 20:41:08xdegayesetfiles: + test_tarfile.patch
keywords: + patch
messages: + msg284931

stage: needs patch -> patch review
2017-01-06 21:30:19xdegayelinkissue26865 dependencies
2017-01-06 21:22:55xdegayesetnosy: + lars.gustaebel
2017-01-06 16:31:35xdegayecreate