Skip to content

Commit

Permalink
Merge branch 'bw/efile_exists' into pu
Browse files Browse the repository at this point in the history
Conflicts:
	erts/emulator/drivers/common/efile_drv.c
	erts/preloaded/src/prim_file.erl
  • Loading branch information
proxyles committed Jan 3, 2012
2 parents ad976b8 + 2759905 commit 5ee5cf4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
29 changes: 29 additions & 0 deletions erts/emulator/drivers/common/efile_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define FILE_FDATASYNC 30
#define FILE_FADVISE 31
#define FILE_SENDFILE 32
#define FILE_EXISTS 33

/* Return codes */

Expand Down Expand Up @@ -1639,6 +1640,22 @@ static void invoke_write_info(void *data)
d->result_ok = efile_write_info(&d->errInfo, &d->info, d->b);
}

static void invoke_file_exists(void *data)
{
struct t_data *d = (struct t_data *) data;
char *path = d->b;
int status;

d->again = 0;
d->errInfo.os_errno = d->errInfo.posix_errno = 0;
status = efile_may_openfile(&d->errInfo, path);
if (!status && d->errInfo.posix_errno != EISDIR) {
errno = ENOENT;
d->errInfo.os_errno = d->errInfo.posix_errno = errno;
}
d->result_ok = status;
}

static void invoke_lseek(void *data)
{
struct t_data *d = (struct t_data *) data;
Expand Down Expand Up @@ -2119,6 +2136,7 @@ file_async_ready(ErlDrvData e, ErlDrvThreadData data)
case FILE_RENAME:
case FILE_WRITE_INFO:
case FILE_FADVISE:
case FILE_EXISTS:
reply(desc, d->result_ok, &d->errInfo);
free_data(data);
break;
Expand Down Expand Up @@ -2624,6 +2642,17 @@ file_output(ErlDrvData e, char* buf, ErlDrvSizeT count)
d->c.fadvise.advise = get_int32(((uchar*) buf) + 2 * sizeof(Sint64));
goto done;
}
case FILE_EXISTS:
{
d = EF_SAFE_ALLOC(sizeof(struct t_data) - 1 + strlen(name) + 1);

strcpy(d->b, name);
d->command = command;
d->invoke = invoke_file_exists;
d->free = free_data;
d->level = 2;
goto done;
}

}

Expand Down
5 changes: 3 additions & 2 deletions erts/emulator/drivers/win32/win_efile.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,14 @@ efile_may_openfile(Efile_error* errInfo, char *name) {
WCHAR *wname = (WCHAR *) name;
DWORD attr;

if ((attr = GetFileAttributesW(wname)) == INVALID_FILE_ATTRIBUTES) {
return check_error(-1, errInfo);
if ((attr = GetFileAttributes(wname)) == INVALID_FILE_ATTRIBUTES) {
return 0;
}

if (attr & FILE_ATTRIBUTE_DIRECTORY) {
errno = EISDIR;
return check_error(-1, errInfo);
return 0;
}
return 1;
}
Expand Down
22 changes: 21 additions & 1 deletion erts/preloaded/src/prim_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
make_symlink/2, make_symlink/3,
read_link/1, read_link/2,
read_link_info/1, read_link_info/2, read_link_info/3,
list_dir/1, list_dir/2]).
list_dir/1, list_dir/2,
exists/1, exists/2]).

%% How to start and stop the ?DRV port.
-export([start/0, stop/1]).

Expand Down Expand Up @@ -100,6 +102,8 @@
-define(FILE_FDATASYNC, 30).
-define(FILE_ADVISE, 31).
-define(FILE_SENDFILE, 32).
-define(FILE_EXISTS, 33).


%% Driver responses
-define(FILE_RESP_OK, 0).
Expand Down Expand Up @@ -901,6 +905,22 @@ list_dir_int(Port, Dir) ->



%% exists/{1,2}

exists(File) ->
exists_int({?DRV, []}, File).

exists(Port, File) when is_port(Port) ->
exists_int(Port, File).

exists_int(Port, File) ->
case drv_command(Port, [?FILE_EXISTS, File, 0]) of
ok -> true;
{error, enoent} -> false;
{error, eisdir} -> {error, eisdir}
end.


%%%-----------------------------------------------------------------
%%% Functions to communicate with the driver

Expand Down

0 comments on commit 5ee5cf4

Please sign in to comment.