From 965db6494f80e4c784aa3bb1cd96dd925ce8b284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Wed, 7 Dec 2011 23:37:11 +0100 Subject: Document file:*_file_info/2 * file:read_file_info/2 * file:write_file_info/3 Document options and time behavior. --- lib/kernel/doc/src/file.xml | 52 ++++++++++++++++++++++++++++++++++----------- lib/kernel/src/file.erl | 10 ++++++--- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index c6a1f25dd9..b2e6962be8 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -149,6 +149,9 @@ + + + @@ -412,7 +415,7 @@ file_info(Filename) -> {ok, FileInfo} | {error, Reason} Get information about a file (deprecated) -

This function is obsolete. Use read_file_info/1 +

This function is obsolete. Use read_file_info/1,2 instead.

@@ -1188,6 +1191,7 @@ + Get information about a file

Retrieves information about a file. Returns @@ -1199,6 +1203,20 @@ from which the function is called:

-include_lib("kernel/include/file.hrl"). +

The time type returned in atime, mtime and ctime + is dependent on the time type set in Opts :: {time, Type}. + Type local will return local time, universal will + return universal time and posix will return seconds since + or before unix time epoch which is 1970-01-01 00:00 UTC. + Default is {time, local}. +

+ +

+ Since file times is stored in posix time on most OS it is + faster to query file information with the posix option. +

+
+

The record file_info contains the following fields.

size = integer() @@ -1213,15 +1231,15 @@

The current system access to the file.

- atime = date_time() + atime = date_time() | integer() -

The last (local) time the file was read.

+

The last time the file was read.

- mtime = date_time() + mtime = date_time() | integer() -

The last (local) time the file was written.

+

The last time the file was written.

- ctime = date_time() + ctime = date_time() | integer()

The interpretation of this time field depends on the operating system. On Unix, it is the last time @@ -1377,9 +1395,11 @@ + Get information about a link or file -

This function works like read_file_info/1, except that +

This function works like + read_file_info/1,2 except that if Name is a symbolic link, information about the link will be returned in the file_info record and the type field of the record will be set to @@ -1690,6 +1710,7 @@ + Change information about a file

Change file information. Returns ok if successful, @@ -1700,18 +1721,25 @@ from which the function is called:

-include_lib("kernel/include/file.hrl"). +

The time type set in atime, mtime and ctime + is dependent on the time type set in Opts :: {time, Type}. + Type local will interpret the time set as local, universal will + interpret it as universal time and posix must be seconds since + or before unix time epoch which is 1970-01-01 00:00 UTC. + Default is {time, local}. +

The following fields are used from the record, if they are given.

- atime = date_time() + atime = date_time() | integer() -

The last (local) time the file was read.

+

The last time the file was read.

- mtime = date_time() + mtime = date_time() | integer() -

The last (local) time the file was written.

+

The last time the file was written.

- ctime = date_time() + ctime = date_time() | integer()

On Unix, any value give for this field will be ignored (the "ctime" for the file will be set to the current diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 7a48d34a09..b253b3e901 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -109,6 +109,10 @@ -type posix_file_advise() :: 'normal' | 'sequential' | 'random' | 'no_reuse' | 'will_need' | 'dont_need'. -type sendfile_option() :: {chunk_size, non_neg_integer()}. +-type file_info_option() :: {'time', 'local'} | {'time', 'universal'} + | {'time', 'posix'}. + + %%%----------------------------------------------------------------- %%% General functions @@ -218,7 +222,7 @@ read_file_info(Name) -> -spec read_file_info(Filename, Opts) -> {ok, FileInfo} | {error, Reason} when Filename :: name(), - Opts :: list(), + Opts :: [file_info_option()], FileInfo :: file_info(), Reason :: posix() | badarg. @@ -240,7 +244,7 @@ read_link_info(Name) -> -spec read_link_info(Name, Opts) -> {ok, FileInfo} | {error, Reason} when Name :: name(), - Opts :: list(), + Opts :: [file_info_option()], FileInfo :: file_info(), Reason :: posix() | badarg. @@ -266,7 +270,7 @@ write_file_info(Name, Info = #file_info{}) -> -spec write_file_info(Filename, FileInfo, Opts) -> ok | {error, Reason} when Filename :: name(), - Opts :: list(), + Opts :: [file_info_option()], FileInfo :: file_info(), Reason :: posix() | badarg. -- cgit v1.2.3