Skip to content

fix(build): handle read-only files on Windows in rmtree to prevent PermissionError (fixes #6808) - #6817

Open
eminsk wants to merge 1 commit into
flet-dev:mainfrom
eminsk:fix/windows-build-permission-error
Open

fix(build): handle read-only files on Windows in rmtree to prevent PermissionError (fixes #6808)#6817
eminsk wants to merge 1 commit into
flet-dev:mainfrom
eminsk:fix/windows-build-permission-error

Conversation

@eminsk

@eminsk eminsk commented Sep 4, 2026

Copy link
Copy Markdown

Summary of Changes

This PR fixes PermissionError: [WinError 5] Access denied on Windows during flet build windows when cleaning up output directories that contain read-only files (such as .git pack/index objects).

Fixes #6808

Root Cause

In flet_cli/commands/build_base.py:

if self.out_dir.exists():
    shutil.rmtree(str(self.out_dir))

On Windows, standard shutil.rmtree without an error handler fails with PermissionError when encountering files with the read-only attribute (stat.S_IREAD), which frequently occur inside .git/objects/pack/ or other build artifacts.

Solution

  1. Added rmtree to flet.utils.files (and re-exported in flet.utils) with an error handler that removes the read-only attribute (os.chmod(path, stat.S_IWRITE)) before retrying deletion. Supports both Python 3.12+ (onexc) and prior versions (onerror).
  2. Updated build_base.py to use rmtree instead of direct shutil.rmtree for directory cleanup.
  3. Added unit tests in sdk/python/packages/flet/tests/test_files.py.

Summary by Sourcery

Make Windows build directory cleanup resilient to read-only files.

Bug Fixes:

  • Prevent Windows build cleanup from failing when output directories contain read-only files.
  • Handle removal of nonexistent directories without raising errors.

Enhancements:

  • Provide a shared recursive directory removal utility with read-only file handling across supported Python versions.

Tests:

  • Add coverage for deleting read-only files and nonexistent directories.

@CLAassistant

CLAassistant commented Sep 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: PermissionError whyle copying build

2 participants