[erlang-questions] Maybe potential incompatibility of file_info record
Shunichi Shinohara
shino.shun@REDACTED
Thu Jun 7 08:52:02 CEST 2018
I looked into the source code and I think the difference between 20
and 21.0-rc2 is identified.
# The subject of this thread is not suitable,
# but please let me report to not leave just a wrong information.
First, the difference between OTP 20.3.4 and 21.0-rc2 is as follows.
(on macOS, OTPs are installed from git by kerl)
Setup file a and b, a is owned by root user.
% rm -f a && rm -f b && sudo touch a && sudo chmod 755 a && touch b
Let's start OTP 21.0-rc2 and read file_info of a and write it to b,
it fails:
% ~/local/otp/OTP-21.0-rc2/bin/erl
Erlang/OTP 21 [RELEASE CANDIDATE 2] [erts-10.0] [source] [64-bit]
[smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [sharing-preserving]
Eshell V10.0 (abort with ^G)
1> {ok, Fi} = file:read_file_info("a").
{ok,#file_info{size = 0,type = regular,access = read,
atime = {{2018,6,7},{15,32,41}},
mtime = {{2018,6,7},{15,32,41}},
ctime = {{2018,6,7},{15,32,41}},
mode = 33261,links = 1,major_device = 16777220,
minor_device = 0,inode = 17846256,uid = 0,gid = 20}}
2> file:write_file_info("b", Fi).
{error,eperm}
Then, start OTP 20.3.4 and replay the same step, it succeeds:
% ~/local/otp/OTP-20.3.4/bin/erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10]
[async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.3 (abort with ^G)
1> {ok, F} = file:read_file_info("a").
{ok,#file_info{size = 0,type = regular,access = read,
atime = {{2018,6,7},{15,32,41}},
mtime = {{2018,6,7},{15,32,41}},
ctime = {{2018,6,7},{15,32,41}},
mode = 33261,links = 1,major_device = 16777220,
minor_device = 0,inode = 17846256,uid = 0,gid = 20}}
2> file:write_file_info("b", F).
ok
The file_info records are the same (sorry again...), but the results differ.
Looking into unix_efile.c on maint-20 branch:
https://github.com/erlang/otp/blob/maint-20/erts/emulator/drivers/unix/unix_efile.c#L572
it ignores eperm error and proceeds forward:
if (chown(name, pInfo->uid, pInfo->gid) && errno != EPERM) {
I'm not sure the difference is judged as incompatibility or not,
it's nice if this note helps someone (including future me).
Thanks,
Shino
2018-06-07 15:07 GMT+09:00 Shunichi Shinohara <shino.shun@REDACTED>:
> I'm sorry I was wrong. Thanks for correct me, Bjorn.
> I have to dig the root cause down ;)
>
> Shino
>
> 2018-06-07 15:04 GMT+09:00 Björn Gustavsson <bjorn@REDACTED>:
>> On Thu, Jun 7, 2018 at 7:39 AM, Shunichi Shinohara <shino.shun@REDACTED> wrote:
>> [...]
>>> It seems that some fields are added to file_info record between 20 and 21-rc2,
>>
>> "Seems"?
>>
>> No fields have been added for a very long time. The only
>> modifications done in recent releases are updates
>> to the types of the existing fields. The last such change
>> was made at the end of 2015.
>>
>> /Bjorn
>>
>> --
>> Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list