micro
micro copied to clipboard
micro cannot edit hidden file on Windows
Description of the problem or steps to reproduce
- Create a text file.
- Make it hidden using Windows Explorer.
- Modify it in micro.
- Try to save.
- 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
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.
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
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?
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