From 3407e53742534f8b16121f4a4d48c58d08776133 Mon Sep 17 00:00:00 2001 From: Johanna Larsson Date: Sun, 8 Sep 2019 13:55:01 +0200 Subject: erl_tar: Fix typespec for create The first argument for `create/3` and `create/4` can be either a `string()` or `binary()` but the typespec says `file:filename()` which is only `string()`. This switches it to `file:filename_all()`. --- lib/stdlib/doc/src/erl_tar.xml | 176 +++++++++-------------------------------- lib/stdlib/src/erl_tar.erl | 17 ++-- 2 files changed, 47 insertions(+), 146 deletions(-) diff --git a/lib/stdlib/doc/src/erl_tar.xml b/lib/stdlib/doc/src/erl_tar.xml index ea8173748a..9be3594724 100644 --- a/lib/stdlib/doc/src/erl_tar.xml +++ b/lib/stdlib/doc/src/erl_tar.xml @@ -125,24 +125,25 @@ + + + + + + + + + + + + - add(TarDescriptor, Filename, Options) -> RetValue + + Add a file to an open tar file. - - TarDescriptor = term() - FilenameOrBin = filename()|binary() - NameInArchive = filename() - Filename = filename()|{NameInArchive,FilenameOrBin} - Options = [Option] - Option = dereference|verbose|{chunks,ChunkSize} - |{atime,non_neg_integer()}|{mtime,non_neg_integer()} - |{ctime,non_neg_integer()}|{uid,non_neg_integer()} - |{gid,non_neg_integer()} - ChunkSize = positive_integer() - RetValue = ok|{error,{Filename,Reason}} - Reason = term() - + +

Adds a file to a tar file that has been opened for writing by open/1.

@@ -211,33 +212,8 @@
- add(TarDescriptor, FilenameOrBin, NameInArchive, Options) -> - RetValue - Add a file to an open tar file. - - TarDescriptor = term() - FilenameOrBin = filename()|binary() - Filename = filename() - NameInArchive = filename() - Options = [Option] - Option = dereference|verbose - RetValue = ok|{error,{Filename,Reason}} - Reason = term() - - -

Adds a file to a tar file that has been opened for writing by - open/2. This function - accepts the same options as - add/3.

-
-
- - - close(TarDescriptor) + Close an open tar file. - - TarDescriptor = term() -

Closes a tar file opened by open/2.

@@ -245,17 +221,9 @@
- create(Name, FileList) ->RetValue + Create a tar archive. - - Name = filename() - FileList = [Filename|{NameInArchive, FilenameOrBin}] - FilenameOrBin = filename()|binary() - Filename = filename() - NameInArchive = filename() - RetValue = ok|{error,{Name,Reason}} - Reason = term() - +

Creates a tar file and archives the files whose names are specified in FileList into it. The files can either be read from disk @@ -264,19 +232,10 @@ - create(Name, FileList, OptionList) + Create a tar archive with options. - - Name = filename() - FileList = [Filename|{NameInArchive, FilenameOrBin}] - FilenameOrBin = filename()|binary() - Filename = filename() - NameInArchive = filename() - OptionList = [Option] - Option = compressed|cooked|dereference|verbose - RetValue = ok|{error,{Name,Reason}} - Reason = term() - + +

Creates a tar file and archives the files whose names are specified in FileList into it. The files can either be read from disk @@ -315,14 +274,8 @@ - extract(Name) -> RetValue + Extract all files from a tar file. - - Name = filename() | {binary,binary()} | {file,Fd} - Fd = file_descriptor() - RetValue = ok|{error,{Name,Reason}} - Reason = term() -

Extracts all files from a tar archive.

If argument Name is specified as {binary,Binary}, @@ -339,20 +292,9 @@ - extract(Name, OptionList) + Extract files from a tar file. - - Name = filename() | {binary,binary()} | {file,Fd} - Fd = file_descriptor() - OptionList = [Option] - Option = {cwd,Cwd}|{files,FileList}|keep_old_files|verbose|memory - Cwd = [dirname()] - FileList = [filename()] - RetValue = ok|MemoryRetValue|{error,{Name,Reason}} - MemoryRetValue = {ok, [{NameInArchive,binary()}]} - NameInArchive = filename() - Reason = term() - +

Extracts files from a tar archive.

If argument Name is specified as {binary,Binary}, @@ -411,11 +353,8 @@ - format_error(Reason) -> string() + Convert error term to a readable string. - - Reason = term() -

Converts an error reason term to a human-readable error message string.

@@ -423,24 +362,11 @@
- init(UserPrivate, AccessMode, Fun) -> - {ok,TarDescriptor} | {error,Reason} + Create a TarDescriptor used in subsequent tar operations when defining own low-level storage access functions. - - UserPrivate = term() - AccessMode = [write] | [read] - Fun when AccessMode is [write] = - fun(write, {UserPrivate,DataToWrite})->...; - (position,{UserPrivate,Position})->...; - (close, UserPrivate)->... end - Fun when AccessMode is [read] = - fun(read2, {UserPrivate,Size})->...; - (position,{UserPrivate,Position})->...; - (close, UserPrivate)->... end - TarDescriptor = term() - Reason = term() - + +

The Fun is the definition of what to do when the different storage operations functions are to be called from the higher tar @@ -518,16 +444,8 @@ erl_tar:close(TarDesc) - open(Name, OpenModeList) -> RetValue + Open a tar file for writing. - - Name = filename() - OpenModeList = [OpenMode] - Mode = write|compressed|cooked - RetValue = {ok,TarDescriptor}|{error,{Name,Reason}} - TarDescriptor = term() - Reason = term() -

Creates a tar file for writing (any existing file with the same name is truncated).

@@ -565,36 +483,23 @@ erl_tar:close(TarDesc)
- table(Name) -> RetValue - Retrieve the name of all files in a tar file. - - Name = filename()|{binary,binary()}|{file,file_descriptor()} - RetValue = {ok,[string()]}|{error,{Name,Reason}} - Reason = term() - - -

Retrieves the names of all files in the tar file Name.

-
-
- - - table(Name, Options) + + Retrieve name and information of all files in a tar file. - - Name = filename()|{binary,binary()}|{file,file_descriptor()} - + + + + +

Retrieves the names of all files in the tar file Name.

- t(Name) + Print the name of each file in a tar file. - - Name = filename()|{binary,binary()}|{file,file_descriptor()} -

Prints the names of all files in the tar file Name to the Erlang shell (similar to "tar t").

@@ -602,12 +507,9 @@ erl_tar:close(TarDesc)
- tt(Name) + Print name and information for each file in a tar file. - - Name = filename()|{binary,binary()}|{file,file_descriptor()} -

Prints names and information about all files in the tar file Name to the Erlang shell (similar to "tar tv").

diff --git a/lib/stdlib/src/erl_tar.erl b/lib/stdlib/src/erl_tar.erl index 7064fcacfa..2dddee632a 100644 --- a/lib/stdlib/src/erl_tar.erl +++ b/lib/stdlib/src/erl_tar.erl @@ -165,7 +165,7 @@ check_extract(Name, #read_opts{files=Files}) -> %%%================================================================ %% The following table functions produce a list of information about %% the files contained in the archive. --type filename() :: string(). +-type name_in_archive() :: string(). -type typeflag() :: regular | link | symlink | char | block | directory | fifo | reserved | unknown. @@ -173,7 +173,7 @@ check_extract(Name, #read_opts{files=Files}) -> -type uid() :: non_neg_integer(). -type gid() :: non_neg_integer(). --type tar_entry() :: {filename(), +-type tar_entry() :: {name_in_archive(), typeflag(), non_neg_integer(), tar_time(), @@ -301,7 +301,7 @@ month(12) -> "Dec". %%%================================================================ %% The open function with friends is to keep the file and binary api of this module --type open_handle() :: file:filename() +-type open_handle() :: file:filename_all() | {binary, binary()} | {file, term()}. -spec open(open_handle(), [write | compressed | cooked]) -> @@ -396,13 +396,13 @@ pad_file(#reader{pos=Pos}=Reader) -> %% Creation/modification of tar archives %% Creates a tar file Name containing the given files. --spec create(file:filename(), filelist()) -> ok | {error, {string(), term()}}. +-spec create(file:filename_all(), filelist()) -> ok | {error, {string(), term()}}. create(Name, FileList) when is_list(Name); is_binary(Name) -> create(Name, FileList, []). %% Creates a tar archive Name containing the given files. %% Accepted options: verbose, compressed, cooked --spec create(file:filename(), filelist(), [create_opt()]) -> +-spec create(file:filename_all(), filelist(), [create_opt()]) -> ok | {error, term()} | {error, {string(), term()}}. create(Name, FileList, Options) when is_list(Name); is_binary(Name) -> Mode = lists:filter(fun(X) -> (X=:=compressed) or (X=:=cooked) @@ -434,9 +434,8 @@ do_create(TarFile, [Name|Rest], Opts) -> end. %% Adds a file to a tape archive. --type add_type() :: string() - | {string(), string()} - | {string(), binary()}. +-type add_type() :: name_in_archive() + | {name_in_archive(), string()|binary()}. -spec add(reader(), add_type(), [add_opt()]) -> ok | {error, term()}. add(Reader, {NameInArchive, Name}, Opts) when is_list(NameInArchive), is_list(Name) -> @@ -448,7 +447,7 @@ add(Reader, Name, Opts) when is_list(Name) -> do_add(Reader, Name, Name, Opts). --spec add(reader(), string() | binary(), string(), [add_opt()]) -> +-spec add(reader(), file:filename_all(), name_in_archive(), [add_opt()]) -> ok | {error, term()}. add(Reader, NameOrBin, NameInArchive, Options) when is_list(NameOrBin); is_binary(NameOrBin), -- cgit v1.2.1