micro icon indicating copy to clipboard operation
micro copied to clipboard

micro cannot edit hidden file on Windows

Open costincaraivan opened this issue 2 years ago • 4 comments

Description of the problem or steps to reproduce

  1. Create a text file.
  2. Make it hidden using Windows Explorer.
  3. Modify it in micro.
  4. Try to save.
  5. Access is denied. -> editing works with VS Code & other editors.

Specifications

Version: 2.0.10
Commit hash: b9763856
Compiled on August 07, 2021

OS: Windows 10 Terminal: Windows Terminal

costincaraivan avatar Dec 08 '22 13:12 costincaraivan

2.0.11 tries to be clever, asks for saving with sudo, but then says that saving with sudo is not supported on Windows (fair).

However, the hidden file category should also be added, since it doesn't actually make the file read-only. It just hides it.

I know that micro is cross platform but hopefully there is a way to check if a file is hidden on Windows with Go.

costincaraivan avatar Dec 08 '22 13:12 costincaraivan

I tried reading the code a bit but files are created or truncated then opened using os.OpenFile when being saved: https://github.com/zyedidia/micro/blob/2d82362a6695a7e898455ce016449167ac439ddd/internal/buffer/save.go#L57

There was this issue when I tried searching about it but I think access is denied when doing that using that function in Windows if the file is hidden: golang/go#25923

niten94 avatar Dec 30 '23 11:12 niten94

sudo is available for windows now https://learn.microsoft.com/en-us/windows/sudo/ and for a long time there's been implementations like gsudo https://github.com/gerardog/gsudo so would it be possible to add sudo support on windows too?

adrianinsaval avatar Aug 04 '24 02:08 adrianinsaval

I do not think administrator privileges should be needed when saving a hidden file so adding sudo support on Windows may not be related with the bug in this issue. Please open another issue about sudo support as a feature request if continuing discussion.

I have not looked at the code and searched much, but it may not be hard adding sudo support on Windows. dd is run when saving files using sudo but dd is not preinstalled and I do not know how would it be solved, especially when considering users not using all Unix tools or knowing where it can be downloaded.

This part in code only will have to be removed when making it at least possible to run sudo: https://github.com/zyedidia/micro/blob/2259fd10affd19be60400a1ac2c86b920f2c64c2/internal/buffer/save.go#L127-L129

niten94 avatar Aug 04 '24 03:08 niten94