← Winnitude! Search  ·  Reader Mode (1277 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 8 LINKS

Windows with_rw-directory TC helper fails to delete repos · Issue #32 · gitpython-developers/gitdb

This repository was archived by the owner on Jul 26, 2026. It is now read-only.

Repository navigation

This repository was archived by the owner on Jul 26, 2026. It is now read-only.

Windows with_rw-directory TC helper fails to delete repos  #32


Open

Open
Windows with_rw-directory TC helper fails to delete repos #32 Labels
acknowledged

tag.leaks

Description

@ankostis's profile ankostis opened on Sep 27, 2016

On Windows, os.rmtree cannot not remove directories with read-only files; such are the git db directories.

The fix is something like this:

           ...
        finally:
            # Need to collect here to be sure all handles have been closed. It appears
            # a windows-only issue. In fact things should be deleted, as well as
            # memory maps closed, once objects go out of scope. For some reason
            # though this is not the case here unless we collect explicitly.
            if not keep:
                gc.collect()

                # From http://stackoverflow.com/a/4829285/548792
                def on_rm_error(func, path, exc_info):
                    import stat
                    os.chmod(path, stat.S_IWRITE)
                    func(path)

                shutil.rmtree(path, onerror=on_rm_error)

Metadata

Metadata

Assignees

No one assigned

    Labels


    acknowledged

    tag.leaks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions