Alien-uv
view release on metacpan or search on metacpan
libuv/test/test-fs.c view on Meta::CPAN
#include <errno.h>
#include <string.h> /* memset */
#include <fcntl.h>
#include <sys/stat.h>
#include <limits.h> /* INT_MAX, PATH_MAX, IOV_MAX */
/* FIXME we shouldn't need to branch in this file */
#if defined(__unix__) || defined(__POSIX__) || \
defined(__APPLE__) || defined(__sun) || \
defined(_AIX) || defined(__MVS__)
#include <unistd.h> /* unlink, rmdir, etc. */
#else
# include <winioctl.h>
# include <direct.h>
# include <io.h>
# ifndef ERROR_SYMLINK_NOT_SUPPORTED
# define ERROR_SYMLINK_NOT_SUPPORTED 1464
# endif
# define unlink _unlink
# define rmdir _rmdir
# define open _open
# define write _write
# define close _close
# ifndef stat
# define stat _stati64
# endif
# ifndef lseek
# define lseek _lseek
# endif
#endif
#define TOO_LONG_NAME_LENGTH 65536
#define PATHMAX 1024
typedef struct {
const char* path;
double atime;
double mtime;
} utime_check_t;
static int dummy_cb_count;
static int close_cb_count;
static int create_cb_count;
static int open_cb_count;
static int read_cb_count;
static int write_cb_count;
static int unlink_cb_count;
static int mkdir_cb_count;
static int mkdtemp_cb_count;
static int rmdir_cb_count;
static int scandir_cb_count;
static int stat_cb_count;
static int rename_cb_count;
static int fsync_cb_count;
static int fdatasync_cb_count;
static int ftruncate_cb_count;
static int sendfile_cb_count;
static int fstat_cb_count;
static int access_cb_count;
static int chmod_cb_count;
static int fchmod_cb_count;
static int chown_cb_count;
static int fchown_cb_count;
static int lchown_cb_count;
static int link_cb_count;
static int symlink_cb_count;
static int readlink_cb_count;
static int realpath_cb_count;
static int utime_cb_count;
static int futime_cb_count;
static uv_loop_t* loop;
static uv_fs_t open_req1;
static uv_fs_t open_req2;
static uv_fs_t read_req;
static uv_fs_t write_req;
static uv_fs_t unlink_req;
static uv_fs_t close_req;
static uv_fs_t mkdir_req;
static uv_fs_t mkdtemp_req1;
static uv_fs_t mkdtemp_req2;
static uv_fs_t rmdir_req;
static uv_fs_t scandir_req;
static uv_fs_t stat_req;
static uv_fs_t rename_req;
static uv_fs_t fsync_req;
static uv_fs_t fdatasync_req;
static uv_fs_t ftruncate_req;
static uv_fs_t sendfile_req;
static uv_fs_t utime_req;
static uv_fs_t futime_req;
static char buf[32];
static char buf2[32];
static char test_buf[] = "test-buffer\n";
static char test_buf2[] = "second-buffer\n";
static uv_buf_t iov;
#ifdef _WIN32
int uv_test_getiovmax(void) {
return INT32_MAX; /* Emulated by libuv, so no real limit. */
}
#else
int uv_test_getiovmax(void) {
#if defined(IOV_MAX)
return IOV_MAX;
#elif defined(_SC_IOV_MAX)
static int iovmax = -1;
if (iovmax == -1) {
iovmax = sysconf(_SC_IOV_MAX);
/* On some embedded devices (arm-linux-uclibc based ip camera),
* sysconf(_SC_IOV_MAX) can not get the correct value. The return
* value is -1 and the errno is EINPROGRESS. Degrade the value to 1.
*/
if (iovmax == -1) iovmax = 1;
}
return iovmax;
#else
return 1024;
#endif
}
#endif
#ifdef _WIN32
/*
* This tag and guid have no special meaning, and don't conflict with
* reserved ids.
*/
static unsigned REPARSE_TAG = 0x9913;
static GUID REPARSE_GUID = {
0x1bf6205f, 0x46ae, 0x4527,
{ 0xb1, 0x0c, 0xc5, 0x09, 0xb7, 0x55, 0x22, 0x80 }};
#endif
static void check_permission(const char* filename, unsigned int mode) {
int r;
uv_fs_t req;
uv_stat_t* s;
r = uv_fs_stat(NULL, &req, filename, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
s = &req.statbuf;
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MSYS__)
/*
* On Windows, chmod can only modify S_IWUSR (_S_IWRITE) bit,
* so only testing for the specified flags.
*/
ASSERT((s->st_mode & 0777) & mode);
#else
ASSERT((s->st_mode & 0777) == mode);
#endif
uv_fs_req_cleanup(&req);
}
static void dummy_cb(uv_fs_t* req) {
(void) req;
dummy_cb_count++;
}
static void link_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_LINK);
ASSERT(req->result == 0);
link_cb_count++;
uv_fs_req_cleanup(req);
}
static void symlink_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_SYMLINK);
ASSERT(req->result == 0);
symlink_cb_count++;
uv_fs_req_cleanup(req);
}
static void readlink_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_READLINK);
ASSERT(req->result == 0);
ASSERT(strcmp(req->ptr, "test_file_symlink2") == 0);
readlink_cb_count++;
uv_fs_req_cleanup(req);
}
static void realpath_cb(uv_fs_t* req) {
char test_file_abs_buf[PATHMAX];
size_t test_file_abs_size = sizeof(test_file_abs_buf);
ASSERT(req->fs_type == UV_FS_REALPATH);
#ifdef _WIN32
/*
* Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
*/
if (req->result == UV_ENOSYS) {
realpath_cb_count++;
uv_fs_req_cleanup(req);
return;
}
#endif
ASSERT(req->result == 0);
uv_cwd(test_file_abs_buf, &test_file_abs_size);
#ifdef _WIN32
strcat(test_file_abs_buf, "\\test_file");
ASSERT(stricmp(req->ptr, test_file_abs_buf) == 0);
#else
strcat(test_file_abs_buf, "/test_file");
ASSERT(strcmp(req->ptr, test_file_abs_buf) == 0);
#endif
realpath_cb_count++;
uv_fs_req_cleanup(req);
}
static void access_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_ACCESS);
access_cb_count++;
uv_fs_req_cleanup(req);
}
static void fchmod_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_FCHMOD);
ASSERT(req->result == 0);
fchmod_cb_count++;
uv_fs_req_cleanup(req);
check_permission("test_file", *(int*)req->data);
}
static void chmod_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_CHMOD);
ASSERT(req->result == 0);
chmod_cb_count++;
uv_fs_req_cleanup(req);
check_permission("test_file", *(int*)req->data);
}
static void fchown_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_FCHOWN);
ASSERT(req->result == 0);
fchown_cb_count++;
uv_fs_req_cleanup(req);
}
static void chown_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_CHOWN);
ASSERT(req->result == 0);
chown_cb_count++;
uv_fs_req_cleanup(req);
}
static void lchown_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_LCHOWN);
ASSERT(req->result == 0);
lchown_cb_count++;
uv_fs_req_cleanup(req);
}
static void chown_root_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_CHOWN);
#if defined(_WIN32) || defined(__MSYS__)
/* On windows, chown is a no-op and always succeeds. */
ASSERT(req->result == 0);
#else
/* On unix, chown'ing the root directory is not allowed -
* unless you're root, of course.
*/
if (geteuid() == 0)
ASSERT(req->result == 0);
else
# if defined(__CYGWIN__)
/* On Cygwin, uid 0 is invalid (no root). */
ASSERT(req->result == UV_EINVAL);
# else
ASSERT(req->result == UV_EPERM);
# endif
#endif
chown_cb_count++;
uv_fs_req_cleanup(req);
}
static void unlink_cb(uv_fs_t* req) {
ASSERT(req == &unlink_req);
ASSERT(req->fs_type == UV_FS_UNLINK);
ASSERT(req->result == 0);
unlink_cb_count++;
uv_fs_req_cleanup(req);
}
static void fstat_cb(uv_fs_t* req) {
uv_stat_t* s = req->ptr;
libuv/test/test-fs.c view on Meta::CPAN
/* File should not exist */
r = uv_fs_access(loop, &req, "test_file", F_OK, access_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(access_cb_count == 1);
access_cb_count = 0; /* reset for the next test */
/* Create file */
r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
/* File should exist */
r = uv_fs_access(NULL, &req, "test_file", F_OK, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/* File should exist */
r = uv_fs_access(loop, &req, "test_file", F_OK, access_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(access_cb_count == 1);
access_cb_count = 0; /* reset for the next test */
/* Close file */
r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/* Directory access */
r = uv_fs_mkdir(NULL, &req, "test_dir", 0777, NULL);
ASSERT(r == 0);
uv_fs_req_cleanup(&req);
r = uv_fs_access(NULL, &req, "test_dir", W_OK, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/*
* Run the loop just to check we don't have make any extraneous uv_ref()
* calls. This should drop out immediately.
*/
uv_run(loop, UV_RUN_DEFAULT);
/* Cleanup. */
unlink("test_file");
rmdir("test_dir");
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(fs_chmod) {
int r;
uv_fs_t req;
uv_file file;
/* Setup. */
unlink("test_file");
loop = uv_default_loop();
r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
iov = uv_buf_init(test_buf, sizeof(test_buf));
r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
ASSERT(r == sizeof(test_buf));
ASSERT(req.result == sizeof(test_buf));
uv_fs_req_cleanup(&req);
#ifndef _WIN32
/* Make the file write-only */
r = uv_fs_chmod(NULL, &req, "test_file", 0200, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
check_permission("test_file", 0200);
#endif
/* Make the file read-only */
r = uv_fs_chmod(NULL, &req, "test_file", 0400, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
check_permission("test_file", 0400);
/* Make the file read+write with sync uv_fs_fchmod */
r = uv_fs_fchmod(NULL, &req, file, 0600, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
check_permission("test_file", 0600);
#ifndef _WIN32
/* async chmod */
{
static int mode = 0200;
req.data = &mode;
}
r = uv_fs_chmod(loop, &req, "test_file", 0200, chmod_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(chmod_cb_count == 1);
chmod_cb_count = 0; /* reset for the next test */
#endif
/* async chmod */
{
static int mode = 0400;
req.data = &mode;
}
r = uv_fs_chmod(loop, &req, "test_file", 0400, chmod_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(chmod_cb_count == 1);
/* async fchmod */
{
static int mode = 0600;
req.data = &mode;
}
r = uv_fs_fchmod(loop, &req, file, 0600, fchmod_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fchmod_cb_count == 1);
close(file);
/*
* Run the loop just to check we don't have make any extraneous uv_ref()
* calls. This should drop out immediately.
*/
uv_run(loop, UV_RUN_DEFAULT);
/* Cleanup. */
unlink("test_file");
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(fs_unlink_readonly) {
int r;
uv_fs_t req;
uv_file file;
/* Setup. */
unlink("test_file");
loop = uv_default_loop();
r = uv_fs_open(NULL,
&req,
"test_file",
O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
iov = uv_buf_init(test_buf, sizeof(test_buf));
r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
ASSERT(r == sizeof(test_buf));
ASSERT(req.result == sizeof(test_buf));
uv_fs_req_cleanup(&req);
close(file);
/* Make the file read-only */
r = uv_fs_chmod(NULL, &req, "test_file", 0400, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
check_permission("test_file", 0400);
/* Try to unlink the file */
r = uv_fs_unlink(NULL, &req, "test_file", NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/*
* Run the loop just to check we don't have make any extraneous uv_ref()
* calls. This should drop out immediately.
*/
uv_run(loop, UV_RUN_DEFAULT);
/* Cleanup. */
uv_fs_chmod(NULL, &req, "test_file", 0600, NULL);
uv_fs_req_cleanup(&req);
unlink("test_file");
MAKE_VALGRIND_HAPPY();
return 0;
}
#ifdef _WIN32
TEST_IMPL(fs_unlink_archive_readonly) {
int r;
uv_fs_t req;
uv_file file;
/* Setup. */
unlink("test_file");
loop = uv_default_loop();
r = uv_fs_open(NULL,
&req,
"test_file",
O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
iov = uv_buf_init(test_buf, sizeof(test_buf));
r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
ASSERT(r == sizeof(test_buf));
ASSERT(req.result == sizeof(test_buf));
uv_fs_req_cleanup(&req);
close(file);
/* Make the file read-only and clear archive flag */
r = SetFileAttributes("test_file", FILE_ATTRIBUTE_READONLY);
ASSERT(r != 0);
uv_fs_req_cleanup(&req);
check_permission("test_file", 0400);
/* Try to unlink the file */
r = uv_fs_unlink(NULL, &req, "test_file", NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/*
* Run the loop just to check we don't have make any extraneous uv_ref()
* calls. This should drop out immediately.
*/
uv_run(loop, UV_RUN_DEFAULT);
/* Cleanup. */
uv_fs_chmod(NULL, &req, "test_file", 0600, NULL);
uv_fs_req_cleanup(&req);
unlink("test_file");
MAKE_VALGRIND_HAPPY();
return 0;
}
#endif
TEST_IMPL(fs_chown) {
int r;
uv_fs_t req;
uv_file file;
/* Setup. */
unlink("test_file");
unlink("test_file_link");
loop = uv_default_loop();
r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
/* sync chown */
r = uv_fs_chown(NULL, &req, "test_file", -1, -1, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/* sync fchown */
r = uv_fs_fchown(NULL, &req, file, -1, -1, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
/* async chown */
r = uv_fs_chown(loop, &req, "test_file", -1, -1, chown_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(chown_cb_count == 1);
#ifndef __MVS__
/* chown to root (fail) */
chown_cb_count = 0;
r = uv_fs_chown(loop, &req, "test_file", 0, 0, chown_root_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(chown_cb_count == 1);
#endif
/* async fchown */
r = uv_fs_fchown(loop, &req, file, -1, -1, fchown_cb);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(fchown_cb_count == 1);
/* sync link */
libuv/test/test-fs.c view on Meta::CPAN
r = uv_fs_mkdir(NULL, NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_mkdtemp(NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_rmdir(NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_scandir(NULL, NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_link(NULL, NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_symlink(NULL, NULL, NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_readlink(NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_realpath(NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_chown(NULL, NULL, NULL, 0, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_fchown(NULL, NULL, 0, 0, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_stat(NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_lstat(NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_fstat(NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_rename(NULL, NULL, NULL, NULL, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_fsync(NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_fdatasync(NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_ftruncate(NULL, NULL, 0, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_copyfile(NULL, NULL, NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_sendfile(NULL, NULL, 0, 0, 0, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_access(NULL, NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_chmod(NULL, NULL, NULL, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_fchmod(NULL, NULL, 0, 0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_utime(NULL, NULL, NULL, 0.0, 0.0, NULL);
ASSERT(r == UV_EINVAL);
r = uv_fs_futime(NULL, NULL, 0, 0.0, 0.0, NULL);
ASSERT(r == UV_EINVAL);
/* This should be a no-op. */
uv_fs_req_cleanup(NULL);
return 0;
}
#ifdef _WIN32
TEST_IMPL(fs_exclusive_sharing_mode) {
int r;
/* Setup. */
unlink("test_file");
ASSERT(UV_FS_O_EXLOCK > 0);
r = uv_fs_open(NULL,
&open_req1,
"test_file",
O_RDWR | O_CREAT | UV_FS_O_EXLOCK,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r >= 0);
ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_open(NULL,
&open_req2,
"test_file",
O_RDONLY | UV_FS_O_EXLOCK,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r < 0);
ASSERT(open_req2.result < 0);
uv_fs_req_cleanup(&open_req2);
r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_open(NULL,
&open_req2,
"test_file",
O_RDONLY | UV_FS_O_EXLOCK,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r >= 0);
ASSERT(open_req2.result >= 0);
uv_fs_req_cleanup(&open_req2);
r = uv_fs_close(NULL, &close_req, open_req2.result, NULL);
ASSERT(r == 0);
libuv/test/test-fs.c view on Meta::CPAN
ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
/* FILE_APPEND_DATA and FILE_FLAG_NO_BUFFERING are mutually exclusive: */
r = uv_fs_open(NULL,
&open_req2,
"test_file",
UV_FS_O_APPEND | UV_FS_O_DIRECT,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r == UV_EINVAL);
ASSERT(open_req2.result == UV_EINVAL);
uv_fs_req_cleanup(&open_req2);
/* Cleanup */
unlink("test_file");
MAKE_VALGRIND_HAPPY();
return 0;
}
#endif
#ifdef _WIN32
int call_icacls(const char* command, ...) {
char icacls_command[1024];
va_list args;
va_start(args, command);
vsnprintf(icacls_command, ARRAYSIZE(icacls_command), command, args);
va_end(args);
return system(icacls_command);
}
TEST_IMPL(fs_open_readonly_acl) {
uv_passwd_t pwd;
uv_fs_t req;
int r;
/*
Based on Node.js test from
https://github.com/nodejs/node/commit/3ba81e34e86a5c32658e218cb6e65b13e8326bc5
If anything goes wrong, you can delte the test_fle_icacls with:
icacls test_file_icacls /remove "%USERNAME%" /inheritance:e
attrib -r test_file_icacls
del test_file_icacls
*/
/* Setup - clear the ACL and remove the file */
loop = uv_default_loop();
r = uv_os_get_passwd(&pwd);
ASSERT(r == 0);
call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e",
pwd.username);
uv_fs_chmod(loop, &req, "test_file_icacls", S_IWUSR, NULL);
unlink("test_file_icacls");
/* Create the file */
r = uv_fs_open(loop,
&open_req1,
"test_file_icacls",
O_RDONLY | O_CREAT,
S_IRUSR,
NULL);
ASSERT(r >= 0);
ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
/* Set up ACL */
r = call_icacls("icacls test_file_icacls /inheritance:r /remove \"%s\"",
pwd.username);
if (r != 0) {
goto acl_cleanup;
}
r = call_icacls("icacls test_file_icacls /grant \"%s\":RX", pwd.username);
if (r != 0) {
goto acl_cleanup;
}
/* Try opening the file */
r = uv_fs_open(NULL, &open_req1, "test_file_icacls", O_RDONLY, 0, NULL);
if (r < 0) {
goto acl_cleanup;
}
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
if (r != 0) {
goto acl_cleanup;
}
uv_fs_req_cleanup(&close_req);
acl_cleanup:
/* Cleanup */
call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e",
pwd.username);
unlink("test_file_icacls");
uv_os_free_passwd(&pwd);
ASSERT(r == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
#endif
#ifdef _WIN32
TEST_IMPL(fs_fchmod_archive_readonly) {
uv_fs_t req;
uv_file file;
int r;
/* Test clearing read-only flag from files with Archive flag cleared */
/* Setup*/
unlink("test_file");
r = uv_fs_open(NULL,
&req,
"test_file",
O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR,
NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0);
uv_fs_req_cleanup(&req);
/* Make the file read-only and clear archive flag */
r = SetFileAttributes("test_file", FILE_ATTRIBUTE_READONLY);
ASSERT(r != 0);
check_permission("test_file", 0400);
/* Try fchmod */
r = uv_fs_open(NULL, &req, "test_file", O_RDONLY, 0, NULL);
ASSERT(r >= 0);
ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
r = uv_fs_fchmod(NULL, &req, file, S_IWUSR, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);
uv_fs_req_cleanup(&req);
r = uv_fs_close(NULL, &req, file, NULL);
ASSERT(r == 0);
uv_fs_req_cleanup(&req);
check_permission("test_file", S_IWUSR);
/* Restore Archive flag for rest of the tests */
r = SetFileAttributes("test_file", FILE_ATTRIBUTE_ARCHIVE);
ASSERT(r != 0);
return 0;
}
#endif
( run in 1.518 second using v1.01-cache-2.11-cpan-0068ddc7af1 )