From 2a1f035f777b5caef0c47dfd863675ef51296c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Wed, 30 Nov 2011 18:41:15 +0100 Subject: Fix validate structure in file_info --- erts/preloaded/src/prim_file.erl | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index b781dffba5..a301abb667 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -773,8 +773,7 @@ write_file_info(File, Info, Opts) -> write_file_info(Port, File, Info, Opts) when is_port(Port) -> write_file_info_int(Port, File, Info, plgv(time, Opts, local)). -write_file_info_int(Port, - File, +write_file_info_int(Port, File, #file_info{mode=Mode, uid=Uid, gid=Gid, @@ -783,16 +782,12 @@ write_file_info_int(Port, ctime=Ctime}, TimeType) -> - %% FIXME: wtf - %% sätt atime beroende på timetype, om ej satt - %% sätt mtime som atime, om ej satt + % Atime and/or Mtime might be undefined + % - use localtime() for atime, if atime is undefined + % - use atime as mtime if mtime is undefined - {Atime, Mtime} = case {Atime0, Mtime0} of - {undefined, Mtime0} -> {erlang:localtime(), Mtime0}; - {Atime0, undefined} -> {Atime0, Atime0}; - {undefined, undefined} -> {erlang:localtime(), erlang:localtime()}; - Complete -> Complete - end, + Atime = file_info_validate_atime(Atime0, TimeType), + Mtime = file_info_validate_mtime(Mtime0, Atime), drv_command(Port, [?FILE_WRITE_INFO, int_to_int32bytes(Mode), @@ -804,6 +799,13 @@ write_file_info_int(Port, pathname(File)]). +file_info_validate_atime(Atime, _) when Atime =/= undefined -> Atime; +file_info_validate_atime(undefined, local) -> erlang:localtime(); +file_info_validate_atime(undefined, utc) -> erlang:universaltime(); +file_info_validate_atime(undefined, epoch) -> datetime_to_epoch(erlang:universaltime()). + +file_info_validate_mtime(undefined, Atime) -> Atime; +file_info_validate_mtime(Mtime, _) -> Mtime. %% make_link/{2,3} -- cgit v1.2.3