Skip to content

Commit

Permalink
Changing File.exists? implementation.
Browse files Browse the repository at this point in the history
Now using file:read_file_info() from Erlang.
  • Loading branch information
philss committed May 5, 2012
1 parent 4da2aaa commit 7a6a711
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,27 @@ defmodule File do

@doc """
Returns if `file` exists
This `file` can be regular file, directory, socket,
symbolic link, named pipe or device file.
## Examples
File.exists?("/tmp")
File.exists?("test/")
#=> true
File.exists?("missing.txt")
#=> false
File.exists?("/dev/null")
#=> true
"""
def exists?(filename) do
is_tuple(FL.last_modified(filename))
case F.read_file_info(filename) do
match: {:ok, _}
true
else:
false
end
end

@doc """
Expand Down
1 change: 1 addition & 0 deletions test/elixir/file_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defmodule FileTest do
test :exists do
assert File.exists?(__FILE__)
assert File.exists?(File.expand_path("../fixtures/foo.txt", __FILE__))
assert File.exists?(File.expand_path("../fixtures/", __FILE__))

refute File.exists?("fixtures/missing.txt")
refute File.exists?("_missing.txt")
Expand Down

0 comments on commit 7a6a711

Please sign in to comment.