Skip to content

built-in touch command returns io error: Access denied (os error 5) on Windows #2388

Closed

Description

@J-F-Liu

bashkit's RealFs::set_modified_time (fs/realfs.rs:748) opens the real file read-only and then calls File::set_modified:

let file = tokio::fs::File::open(&real).await?.into_std().await;
tokio::task::spawn_blocking(move || file.set_modified(time))

What File::set_times/set_modified does with that handle is platform-specific:

Platform std implementation Gate
Linux libc::futimens(fd, …) (sys/fs/unix.rs:1764) process owns the file or has write permission on it — nothing about the fd's open mode
macOS fsetattrlist(fd, …) (same access model) same
Windows SetFileTime(handle, …) (sys/fs/windows.rs:813) handle must carry FILE_WRITE_ATTRIBUTES/GENERIC_WRITE

tokio::fs::File::open yields GENERIC_READ on Windows, so SetFileTime returns ERROR_ACCESS_DENIED → os error 5.

Activity

  1. chaliy commented on Sep 10, 2026

    @chaliy
    Contributor

    Addressed would be released soon

  2. chaliy commented on Sep 10, 2026

    @chaliy
    Contributor

    @J-F-Liu check if fix works for you, feel free to reopen

  3. J-F-Liu commented on Sep 21, 2026

    @J-F-Liu
    Author

    The fix works, thanks.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions