Question

Python's shutil.copytree is not very flexible; what is the simplest way to add support for ignoring permissions while copying in copytree (without having to re-write its implementation)?

Otherwise, copytree fails like this:

(…)”[Errno 45] Operation not supported: ‘/path/foo/bar’”
Was it helpful?

Solution

You have shutil.py in your standard Python distribution (on Ubuntu, mine is under /usr/lib/python2.6 for instance; Windows might be C:\Python26\lib?). The copytree function is only 38 lines long (34 if you don't count comments), and the end of the docstring explicitly states:

XXX Consider this example code rather than the ultimate tool.

So the simplest way really would be to change/add a couple lines to copytree, or find another library, to be honest.

OTHER TIPS

Not thread-safe (or advisable in general) but OK for a throwaway script:

import shutil

_orig_copystat = shutil.copystat
shutil.copystat = lambda x, y: x

shutil.copytree(src, dst)

shutil.copystat = _orig_copystat
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top