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.

Author paul.moore
Recipients paul.moore
Date 2014-07-22.19:54:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406058870.67.0.270826115135.issue22040@psf.upfronthosting.co.za>
In-reply-to
Content
It would be useful for shutil.rmtree to have a "force" argument that overrode read-only permission issues, essentially replicating the behaviour of the -f flag in rm -rf (Unix) and the -force parameter of del (Windows Powershell).

It's possible to use the onerror callback to implement this, but it's tricky to get right in a cross-platform manner. See http://stackoverflow.com/questions/2656322, which recommends

def onerror(func, path, exc_info):
    if not os.access(path, os.W_OK):
        os.chmod(path, stat.S_IWUSR)
        func(path)
    else:
        raise

and http://stackoverflow.com/questions/1889597 which recommends

def remove_readonly(func, path, excinfo):
    os.chmod(path, stat.S_IWRITE)
    func(path)

It's not clear whether either of these is portable, though (the former looks to me like it's Unix-specific and the latter like it's for Windows, but I'm not sure).

Having the functionality available in the standard library function directly avoids having people write tricky and potentially buggy code for what is a pretty common situation. (In particular, this comes up a lot in code that deletes git checkouts on Windows, where git makes parts of the .git directory readonly).
History
Date User Action Args
2014-07-22 19:54:30paul.mooresetrecipients: + paul.moore
2014-07-22 19:54:30paul.mooresetmessageid: <1406058870.67.0.270826115135.issue22040@psf.upfronthosting.co.za>
2014-07-22 19:54:30paul.moorelinkissue22040 messages
2014-07-22 19:54:30paul.moorecreate