Skip to content

Tox cannot remove readonly files from tmp directory #2498

Closed
@robgom

Description

@robgom

When there are some read-only files left in tmp directory, they are not cleared upon next execution.

Cleaning is done in ensure_empty_dir.

Changing it to the following code fixes the problem:

import os, stat
import shutil

from tox import reporter


def ensure_empty_dir(path):
    if path.check():
        reporter.info("  removing {}".format(path))
        shutil.rmtree(str(path), onerror=remove_readonly)  # originally without onerror, just with ignore_errors
        path.ensure(dir=1)

def remove_readonly(func, path, _):
    "Clear the readonly bit and reattempt the removal"
    os.chmod(path, stat.S_IWRITE)
    func(path)

In our case those read-only files come from externally executed commands and they affect subsequent tests execution.
As a workaround we'd consider cleaning them ourselves.

Reproducible: always
Platform: win32 (Windows 10), Python 3.9
Tox version: tox==3.25.1

Please let me know if you need more information.
I can try providing self-reproducible setup, but might take a while.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:normalaffects many people or has quite an impacthelp:wantedIssues that have been acknowledged, a solution determined and a PR might likely be accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions