twpayne/chezmoi

chezmoi: open C:/.../desktop.ini: Access is denied.

Closed this issue · 5 comments

Describe the bug

Applying changes to desktop.ini files on Windows fails with Access is denied.

To reproduce

  • Add existing folder with desktop.ini to chezmoi source (e.g. Desktop or Downloads)
  • Edit desktop.ini in source state
  • Try to apply changes

Expected behavior

Successful apply

Output of command with the --verbose flag

$ chezmoi --verbose apply
chezmoi: open C:/Users/Max/Desktop/Games/desktop.ini: Access is denied.
diff --git a/Desktop/Games/desktop.ini b/Desktop/Games/desktop.ini
index 32e572b3d0bb86ed96cb6fe1955b7fb8aad38beb..d142effdc0d4e04aa4f8f360378571b7a5ba1a62 100666
--- a/Desktop/Games/desktop.ini
+++ b/Desktop/Games/desktop.ini
@@ -1,6 +1,2 @@
 [.ShellClassInfo]
-IconResource=C:\WINDOWS\System32\networkexplorer.dll,15^M
-[ViewState]^M
-Mode=^M
-Vid=^M
-FolderType=Generic^M
+IconResource=%SystemRoot%\networkexplorer.dll,15^M

Output of chezmoi doctor

$ chezmoi doctor
RESULT    CHECK                       MESSAGE
ok        version                     v2.47.2, commit f4904293d9e3d5297f481b0b1ec00981716fff39, built at 2024-03-17T18:42:28Z, built by goreleaser
ok        latest-version              v2.47.2
ok        os-arch                     windows/amd64
ok        systeminfo                  Microsoft Windows 10 Pro (10.0.19045 N/A Build 19045)
ok        go-version                  go1.22.1 (gc)
ok        executable                  ~/.local/bin/chezmoi.exe
ok        upgrade-method              replace-executable
ok        config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2024-03-24T19:18:53+03:00
ok        source-dir                  ~/.local/share/chezmoi is a git working tree (clean)
warning   suspicious-entries          ~/.local/share/chezmoi/.chezmoiexternal.yml.tmpl and ~/.local/share/chezmoi/dot_config/rootmoi/chezmoi.yaml.tmpl
ok        working-tree                ~/.local/share/chezmoi is a git working tree (clean)
ok        dest-dir                    ~ is a directory
ok        cd-command                  found C:/Windows/system32/cmd.exe
ok        cd-args                     'C:\\Windows\\system32\\cmd.exe'
info      diff-command                not set
ok        edit-command                found ~/.local/bin/uni-editor.bat
ok        edit-args                   '~/.local/bin/uni-editor.bat'
ok        git-command                 found C:/Program Files/Git/cmd/git.exe, version 2.44.0
warning   merge-command               vimdiff not found in $PATH
ok        shell-command               found C:/Windows/system32/cmd.exe
ok        shell-args                  'C:\\Windows\\system32\\cmd.exe'
info      age-command                 age not found in $PATH
info      gpg-command                 gpg not found in $PATH
info      pinentry-command            not set
info      1password-command           op not found in $PATH
info      bitwarden-command           bw not found in $PATH
info      bitwarden-secrets-command   bws not found in $PATH
info      dashlane-command            dcli not found in $PATH
info      doppler-command             doppler not found in $PATH
info      gopass-command              gopass not found in $PATH
info      keepassxc-command           keepassxc-cli not found in $PATH
info      keepassxc-db                not set
info      keeper-command              keeper not found in $PATH
info      lastpass-command            lpass not found in $PATH
info      pass-command                pass not found in $PATH
info      passhole-command            ph not found in $PATH
info      rbw-command                 rbw not found in $PATH
info      vault-command               vault not found in $PATH
info      vlt-command                 vlt not found in $PATH
info      secret-command              not set

Can you edit a desktop.ini file with notepad?

Yes. Both notepad.exe and Notepad++ are able to edit desktop.ini files

This is likely some weird Windows permission configuration. chezmoi does not have any special handling for .ini files.

Reading a bit more about it, Desktop.ini files in Windows need the read-only and hidden attributes, which are not supported by chezmoi.

You can use a run_before_ script to clear these attributes before chezmoi writes the file and a run_after_ script to restore them.

See also #2812 and #3392.

Thanks