Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python shutil.copytree - ignore permissions

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’”
like image 713
Sridhar Ratnakumar Avatar asked Aug 20 '09 00:08

Sridhar Ratnakumar


1 Answers

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
like image 171
Jamie Avatar answered Sep 19 '22 14:09

Jamie