unix: implement uv_fs_lstat
This commit is contained in:
parent
dbc1cb0e66
commit
a6ed1757ab
@ -57,6 +57,7 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
|
||||
break;
|
||||
|
||||
case UV_FS_STAT:
|
||||
case UV_FS_LSTAT:
|
||||
req->ptr = NULL;
|
||||
break;
|
||||
|
||||
@ -98,7 +99,7 @@ static int uv__fs_after(eio_req* eio) {
|
||||
}
|
||||
req->ptr = malloc(buflen);
|
||||
memcpy(req->ptr, req->eio->ptr2, buflen);
|
||||
} else if (req->fs_type == UV_FS_STAT) {
|
||||
} else if (req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT) {
|
||||
req->ptr = req->eio->ptr2;
|
||||
}
|
||||
|
||||
@ -548,12 +549,53 @@ int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_c
|
||||
|
||||
|
||||
int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
||||
assert(0 && "implement me");
|
||||
return -1;
|
||||
char* pathdup = path;
|
||||
int pathlen;
|
||||
|
||||
uv_fs_req_init(req, UV_FS_LSTAT, cb);
|
||||
|
||||
/* TODO do this without duplicating the string. */
|
||||
/* TODO security */
|
||||
pathdup = strdup(path);
|
||||
pathlen = strlen(path);
|
||||
|
||||
if (pathlen > 0 && path[pathlen - 1] == '\\') {
|
||||
/* TODO do not modify input string */
|
||||
pathdup[pathlen - 1] = '\0';
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
/* async */
|
||||
uv_ref();
|
||||
req->eio = eio_lstat(pathdup, EIO_PRI_DEFAULT, uv__fs_after, req);
|
||||
|
||||
free(pathdup);
|
||||
|
||||
if (!req->eio) {
|
||||
uv_err_new(NULL, ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* sync */
|
||||
req->result = lstat(pathdup, &req->statbuf);
|
||||
|
||||
free(pathdup);
|
||||
|
||||
if (req->result < 0) {
|
||||
uv_err_new(NULL, errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
req->ptr = &req->statbuf;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) {
|
||||
int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path,
|
||||
uv_fs_cb cb) {
|
||||
assert(0 && "implement me");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ static void readdir_cb(uv_fs_t* req) {
|
||||
|
||||
static void stat_cb(uv_fs_t* req) {
|
||||
ASSERT(req == &stat_req);
|
||||
ASSERT(req->fs_type == UV_FS_STAT);
|
||||
ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
|
||||
ASSERT(req->result != -1);
|
||||
ASSERT(req->ptr);
|
||||
stat_cb_count++;
|
||||
@ -435,11 +435,20 @@ TEST_IMPL(fs_async_dir) {
|
||||
r = uv_fs_stat(&stat_req, "test_dir", stat_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run();
|
||||
|
||||
r = uv_fs_stat(&stat_req, "test_dir\\", stat_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run();
|
||||
|
||||
ASSERT(stat_cb_count == 2);
|
||||
r = uv_fs_lstat(&stat_req, "test_dir", stat_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run();
|
||||
|
||||
r = uv_fs_lstat(&stat_req, "test_dir\\", stat_cb);
|
||||
ASSERT(r == 0);
|
||||
uv_run();
|
||||
|
||||
ASSERT(stat_cb_count == 4);
|
||||
|
||||
r = uv_fs_unlink(&unlink_req, "test_dir/file1", unlink_cb);
|
||||
ASSERT(r == 0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user