Issue 28627: [alpine] shutil.copytree fail to copy a direcotry with broken symlinks (original) (raw)
Created on 2016-11-06 22:34 by fruch, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (4)
Author: Israel Fruchter (fruch)
Date: 2016-11-06 22:34
this fails on python3.5-alpine and python3.6-alpine (works as fine in python2.7-alpine)
cd /bug && ln -s /broken_path/to_nowhere broken python -c "import shutil; shutil.copytree('/bug', '/temp', symlinks=True)"
Dockerfile example here: https://github.com/docker-library/python/issues/155
https://github.com/python/cpython/blob/c30098c8c6014f3340a369a31df9c74bdbacc269/Lib/shutil.py#L198
seem like its suppressing NotImplementedError, and in our case OsError with ENOSUP was raised
Author: Israel Fruchter (fruch)
Date: 2016-11-06 22:36
the failure looks like that:
Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.5/shutil.py", line 359, in copytree raise Error(errors) shutil.Error: [('/bug/broken', '/temp/broken', "[Errno 95] Not supported: '/temp/broken'")]
Author: Max Rees (sroracle) *
Date: 2018-04-19 02:54
Actually the symlinks don't need to be broken. It fails for any kind of symlink on musl.
$ ls -l /tmp/symtest lrwxrwxrwx 1 mcrees mcrees 10 Apr 18 21:16 empty -> /var/empty -rw-r--r-- 1 mcrees mcrees 0 Apr 18 21:16 regular lrwxrwxrwx 1 mcrees mcrees 16 Apr 18 21:16 resolv.conf -> /etc/resolv.conf
$ python3
import shutil; shutil.copytree('/tmp/symtest', '/tmp/symtest2', symlinks=True) shutil.Error: [('/tmp/symtest/resolv.conf', '/tmp/symtest2/resolv.conf', "[Errno 95] Not supported: '/tmp/symtest2/resolv.conf'"), ('/tmp/symtest/empty', '/tmp/symtest2/empty', "[Errno 95] Not supported: '/tmp/symtest2/empty'")]
$ ls -l /tmp/symtest2 total 0 lrwxrwxrwx 1 mcrees mcrees 10 Apr 18 21:16 empty -> /var/empty -rw-r--r-- 1 mcrees mcrees 0 Apr 18 21:16 regular lrwxrwxrwx 1 mcrees mcrees 16 Apr 18 21:16 resolv.conf -> /etc/resolv.conf
The implication of these bugs mean that things like pip may fail if it calls shutil.copytree(..., symlinks=True) on a directory that contains symlinks(!)
Attached is a patch that works around the issue but does not address why chmod is returning OSError instead of NotImplementedError.
Author: Martin Panter (martin.panter) *
Date: 2018-04-20 21:23
This looks like it may be covered by Issue 31940, about the “shutil.copystat” API. See Anthony’s initial proposal at <https://bugs.python.org/issue31940#msg305528>.
Max: I think you need the “else” branch to reraise the exception if “errno” doesn’t match. Perhaps a test case would have picked this up.
History
Date
User
Action
Args
2022-04-11 14:58:39
admin
set
github: 72813
2019-02-11 01:53:13
benjamin.peterson
set
status: open -> closed
resolution: duplicate
stage: resolved
2018-04-20 21:23:16
martin.panter
set
superseder: copystat on symlinks fails for alpine -- faulty lchmod implementation?
messages: +
nosy: + martin.panter
2018-04-19 02:54:31
sroracle
set
files: + musl-eopnotsupp.patch
nosy: + sroracle
messages: +
keywords: + patch
2016-11-06 22:36:28
fruch
set
messages: +
2016-11-06 22:34:31
fruch
create