GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True · Issue #140774 · python/cpython

Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True #140774

New issue
Copy link
New issue
Copy link
Open
#154852
Open
Path.chmod() silently fails on Windows when archive bit is cleared and follow_symlinks=True#140774
#154852
Copy link
Labels
OS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@kmray
kmray
opened on Oct 30, 2025
Issue body actions

Bug report

Bug description:

Expected behavior:

  • Path.chmod(stat.S_IWRITE | stat.S_IREAD) should clear the read-only attribute regardless of archive bit state
  • Path.chmod(stat.S_IWRITE | stat.S_IREAD) should match os.chmod() behavior

Actual behavior:

  • When archive bit is cleared, Path.chmod(stat.S_IWRITE | stat.S_IREAD) silently fails to clear read-only
  • When archive bit is set, it works correctly
  • Path.chmod(stat.S_IWRITE | stat.S_IREAD, follow_symlinks=False) always works
import os
import stat
import subprocess
from pathlib import Path


def is_read_only(file: str | os.PathLike) -> bool:
    return os.stat(file).st_file_attributes & stat.FILE_ATTRIBUTE_READONLY > 0


test_file = Path('test.txt')
test_file.touch()

subprocess.run(f'attrib -a +r {test_file}', check=True)
print(f'Initial (no archive): Read Only: {is_read_only(test_file)}')

test_file.chmod(stat.S_IWRITE | stat.S_IREAD)
print(f'After chmod(follow_symlinks=True): Read Only: {is_read_only(test_file)}')

test_file.chmod(stat.S_IWRITE | stat.S_IREAD, follow_symlinks=False)
print(f'After chmod(follow_symlinks=False): {is_read_only(test_file)}')

subprocess.run(f'attrib +a +r {test_file}', check=True)
print(f'Initial (archive): Read Only: {is_read_only(test_file)}')

test_file.chmod(stat.S_IWRITE | stat.S_IREAD)
print(f'After chmod(follow_symlinks=True): Read Only: {is_read_only(test_file)}')

test_file.chmod(stat.S_IWRITE | stat.S_IREAD, follow_symlinks=False)
print(f'After chmod(follow_symlinks=False): {is_read_only(test_file)}')

Output

Initial (no archive): Read Only: True
After chmod(follow_symlinks=True): Read Only: True
After chmod(follow_symlinks=False): False
Initial (archive): Read Only: True
After chmod(follow_symlinks=True): Read Only: False
After chmod(follow_symlinks=False): False

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs

  • gh-140774: Fix pathlib.Path.chmod handling of Windows Archive bit #142018
  • gh-140774: Fix clearing the read-only file attribute on Windows #154852

Activity

  1. kmray
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 30, 2025
  2. cmaloney
    added
    OS-windows
    on Oct 30, 2025
  3. StanFromIreland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-pathlib
    on Oct 30, 2025
  4. pareshjoshij
    added 2 commits that reference this issue on Nov 27, 2025

    pythongh-140774: Fix pathlib.Path.chmod not handling the Archive bit …

    9cf6cd7

    Fix pythongh-140774: os.chmod fails to clear Read-Only if Archive bit…

    25cc0a2
  5. yhay81
    added 2 commits that reference this issue on Nov 12, 2026

    Merge remote-tracking branch 'upstream/main' into pythongh-140774-hch…

    3b50d3d

    pythongh-140774: Set SetFileAttributesW argtypes and cover fd/Path.chmod

    80c74d0
  6. yhay81 commented on Nov 12, 2026

    @yhay81
    yhay81
    on Nov 12, 2026
    More actions

    Root-cause note for triage: although reported via Path.chmod(), the bug is in win32_hchmod() (Modules/posixmodule.c, introduced in GH-113049 / GH-113192), affecting os.chmod(..., follow_symlinks=True), os.chmod(fd, ...), os.fchmod(), and Path.chmod() alike (os.chmod() on Windows defaults to follow_symlinks=False, which goes through SetFileAttributesW() instead).

    Newly created files on NTFS carry FILE_ATTRIBUTE_ARCHIVE (0x20), so clearing FILE_ATTRIBUTE_READONLY (0x01) normally leaves info.FileAttributes != 0. When READONLY is the sole attribute (e.g. after attrib -a +r), info.FileAttributes &= ~FILE_ATTRIBUTE_READONLY yields 0, which FILE_BASIC_INFO documents as leaving attributes unchanged rather than clearing them; FILE_ATTRIBUTE_NORMAL must be passed instead. Fix and regression tests are in #154852.

  7. yhay81
    added a commit that references this issue on Nov 12, 2026

    pythongh-140774: Remove redundant Path.chmod() test from Win32ChmodTests

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.