Closed nicbet closed 4 years ago
@nicbet As a windows user, what would you do to fix windows giving an invalid access
error upon accessing a file?
For what it's worth I've been tracing the code by hand and here is something interesting:
elixir_utils
calls file:write_file_info(Name, #file_info{mtime=Time}, [{time, universal}]).
On Windows, if I simulate this call like this:
defmodule XFile do
require Record
Record.defrecord(:file_info, Record.extract(:file_info, from_lib: "kernel/include/file.hrl"))
end
require XFile
finfo = XFile.file_into(mtime: :calendar.universal_time())
which return me a
{:file_info, :undefined, :undefined, :undefined, :undefined,
{{2018, 11, 1}, {17, 21, 20}}, :undefined, :undefined, :undefined, :undefined,
:undefined, :undefined, :undefined, :undefined}
and then calling
:file.write_file_info("test.txt", finfo)
I get exactly the same error {:error, :einval}
. On Mac OS X, the same code results in an :ok
I can get the call in Windows to succeed if I specify the file info fully:
finfo = {:file_info, 0, :regular, :read_write, {{2018, 11, 1}, {13, 3, 27}},
{{2018, 11, 1}, {13, 4, 28}}, {{2018, 11, 1}, {13, 4, 28}}, 33188, 1, 13, 0,
449, 1000, 1000}
:file.write_file_info("test.txt", finfo)
:ok
it appears that if uid
and gid
are :undefined
, :prim_file.write_file_info_1
calls an internal set_owner
which sets uid
and gid
to -1
which causes the {:error, :einval}
:
finfo = {:file_info, 0, :regular, :read_write, {{2018, 11, 1}, {13, 3, 27}},
{{2018, 11, 1}, {13, 4, 28}}, {{2018, 11, 1}, {13, 4, 28}}, 33188, 1, 13, 0,
449, -1, -1}
:file.write_file_info("test.txt", finfo)
{:error, :einval}
@nicbet Thank you for investigating this.
Do we know if it's the correct behavior to set uid/gid
to -1
? It was my understanding that OTP would only modify the properties where the value != :undefined
.
The plot thickens, ... a small C
program:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
int main() {
char path[] = "test.txt";
int ret = chown(path, -1, -1);
if (ret != 0) {
perror("chown");
printf("\n Error val: %d\n", errno);
}
return ret;
}
On Mac OS X returns 0, on Windows returns errno
of 22
which is EINVAL
.
So apparently WSL does not support "-1" for either gid
or uid
, even though the spec (http://pubs.opengroup.org/onlinepubs/7908799/xsh/chown.html) says If owner or group is specified as (uid_t)-1 or (gid_t)-1 respectively, the corresponding ID of the file is unchanged.
So sounds like a WSL bug then indeed, hrmm...
I think it's also worth mentioning that for anyone who encounters this problem, for now be aware that this issue only manifests on mounted (DrvFS) file systems.
You can still do you Elixir development on your root filesystem (cd ~
).
So that means that at the present it ‘ s not possibile to use Elixir and Docker on WSL correct? I think this is quite a big issue...Any hope that Microsoft will address it?
From what I've seen reading through the open bug reports over on the WSL GitHub, it appears that the nodejs/yarn community is hitting a similar, possibly the same bug, which appears to have been fixed in Windows 1809. I was looking to update to see if 1809 fixes the issue, but alas MSFT has for now stopped rolling out the 1809 upgrade. When 1809 rolls out and the issue persists, I think we should open new bug over at WSL.
Ok thanks a lot for your feedback. I’ll go back to local development while keeping an eye to the Windows update.
Good news! I just updated to Windows 10 build 1809, and the issue seems to be fixed.
The C
program, as well as Erlang/OTPs chown
call with -1
as uid now work correctly and return 0
.
I just wanted to jump in, I'm having the same issue. I'm on NTFS but I'm not using WSL.
I am also getting this issues on both windows 1803 and 1809 not using WSL.
We have noticed tarballs with symlinks can have issues on Windows so that is worth looking into for people have have this issue. The Hex team cannot reproduce this issue so we are closing it for now. If you have more information please post it here or open a new issue. Thank your for the report!
Observed behaviour:
Expected behaviour: dependencies fetched successfully.
Note that the issue also manifests as: