microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.41k stars 822 forks source link

[WSL 2] Can not save file on Linux fs from Windows emacs #6004

Open rickardlind opened 4 years ago

rickardlind commented 4 years ago

Environment

Microsoft Windows [Version 10.0.19041.508] Ubuntu 20.04 on WSL 2 Linux version 4.19.104-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Feb 19 06:37:35 UTC 2020

Steps to reproduce

  1. Install Emacs for Windows from GNU
  2. Create text file in WSL:
    
    $ pwd
    /home/rille

$ echo "Foo" > TEST

3. Open file with Windows Emacs:

$ /mnt/c/Program/Emacs/x86_64/bin/runemacs.exe TEST

4. Edit file, then try to save with `Ctrl+X Ctrl-S`. Produces error message:

Getting ACLs: Input/output error, //wsl$/Ubuntu-20.04/home/rille/TEST



If Emacs is started with the name of a non-existing file, it can be saved once.
With an earlier version of Emacs (26.1) the file would be written but any execute bits would be stripped.

#  Expected behavior

The file is saved.

# Actual behavior

Emacs shows an error message and refuses to save the file.
therealkenc commented 4 years ago

Early guess, probably external (in other words recent emacs regress) like this. Not all Windows filesystems supports Windows ACLs, including our 9p.

rwellscs commented 3 years ago

I am running into this problem as well, on 2020-12-21, with this environment:

Windows 10 Version 1909 (OS Build 18363.1198) Ubuntu 20.04 LTS on WSL 2 Linux PALN34691146A 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

I also experienced that if I create a file that does not exist it can be saved, but any modification to an existing file gets this error.

dominiksta commented 3 years ago

Can confirm this is still an issue (OS Build 19042.1110, Emacs 27.2, using both WSL 1 and WSL 2).

Although this maybe should be reported to emacs-devel instead, I thought this might help some people when posted here: A very crude fix I came up with is to simply add advice around file-acl:

(when (eq system-type 'windows-nt)
    (defun fp/ignore-wsl-acls (orig-fun &rest args)
      "Ignore ACLs on WSL. WSL does not provide an ACL, but emacs
expects there to be one before saving any file. Without this
advice, files on WSL can not be saved."
      (if (string-match-p "^//wsl\$/" (car args))
          (progn (message "ignoring wsl acls") "")
        (apply orig-fun args)))

    (advice-add 'file-acl :around 'fp/ignore-wsl-acls))

So far I have not encountered any issues with this, although one should always be careful when writing advice for "low-level" functions like file-acl. Realistically, running emacs directly in wsl is a better option, but if you just want to make some quick edits in wsl while doing most of your work on the windows side of things, this might be a decent fix.

chriskorosu commented 2 years ago

This is very strange. I have two files in the same directory, one of which generates this error, one of which doesn't (multiple saves).

Dominiksta's workaround worked for me. Thanks!

rwellscs commented 2 years ago

Dominiksta's workaround continues to work for me; I have not checked recently to see if it is still required.

OS Win 10 21H2 build 19044.1526 WSL2; Emacs 27.2, build 1, x86_64-w64-mingw32 of 2021-03-26. Linux-r: 5.10.16.3-microsoft-standard-WSL2 Linux-v: #1 SMP Fri Apr 2 22:23:49 UTC 2021

Thanks!

DaveLaur commented 11 months ago

Can confirm this is still an issue (OS Build 19042.1110, Emacs 27.2, using both WSL 1 and WSL 2).

Although this maybe should be reported to emacs-devel instead, I thought this might help some people when posted here: A very crude fix I came up with is to simply add advice around file-acl:

(when (eq system-type 'windows-nt)
    (defun fp/ignore-wsl-acls (orig-fun &rest args)
      "Ignore ACLs on WSL. WSL does not provide an ACL, but emacs
expects there to be one before saving any file. Without this
advice, files on WSL can not be saved."
      (if (string-match-p "^//wsl\$/" (car args))
          (progn (message "ignoring wsl acls") "")
        (apply orig-fun args)))

    (advice-add 'file-acl :around 'fp/ignore-wsl-acls))

So far I have not encountered any issues with this, although one should always be careful when writing advice for "low-level" functions like file-acl. Realistically, running emacs directly in wsl is a better option, but if you just want to make some quick edits in wsl while doing most of your work on the windows side of things, this might be a decent fix.

Thank you @dominiksta `` for that excellent workaround. I've updated it for my own situation when using rclone, and the filename doesn't necessarily tell you what the mount is. It catches the error thrown by file-acl instead of preventing the function from running:

(defun fp/ignore-acls (orig-fun &rest args)
  "Ignore ACLs when not available.  rclone does not provide an ACL."
  (condition-case nil
      (orig-fun (car args))
    (error "")))

(advice-add 'file-acl :around 'fp/ignore-acls)

Hope others also find this useful