Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micro cannot edit hidden file on Windows #2660

Open
costincaraivan opened this issue Dec 8, 2022 · 4 comments
Open

micro cannot edit hidden file on Windows #2660

costincaraivan opened this issue Dec 8, 2022 · 4 comments

Comments

@costincaraivan
Copy link

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
Copy link
Author

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.

@niten94
Copy link
Contributor

niten94 commented Dec 30, 2023

I tried reading the code a bit but files are created or truncated then opened using os.OpenFile when being saved:

} else if writeCloser, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {

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

@adrianinsaval
Copy link

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?

@niten94
Copy link
Contributor

niten94 commented Aug 4, 2024

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:

if withSudo && runtime.GOOS == "windows" {
return errors.New("Save with sudo not supported on Windows")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants