Commit bbadba6b authored by sbc's avatar sbc Committed by Commit bot

[NaCl SDK] nacl_io: Remove Node::Access method.

This is implemented generically in terms of GetStat().

Review URL: https://codereview.chromium.org/547053002

Cr-Commit-Position: refs/heads/master@{#294057}
parent d719be84
......@@ -240,21 +240,6 @@ Error FsNode::VIoctl(int request, va_list args) {
} // namespace
Error DevFs::Access(const Path& path, int a_mode) {
ScopedNode node;
int error = root_->FindChild(path.Join(), &node);
if (error)
return error;
// Don't allow execute access.
if (a_mode & X_OK) {
LOG_TRACE("Executing devfs nodes is not allowed.");
return EACCES;
}
return 0;
}
Error DevFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL);
int error;
......
......@@ -14,7 +14,6 @@ class Node;
class DevFs : public Filesystem {
public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int open_flags, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
......
......@@ -62,10 +62,6 @@ class Filesystem : public sdk_util::RefObject {
// All paths in functions below are expected to containing a leading "/".
// Test whether a file or directory at a given path can be accessed.
// Returns 0 on success, or an appropriate errno value on failure.
virtual Error Access(const Path& path, int a_mode) = 0;
// Open a node at |path| with the specified open flags. The resulting
// Node is created with a ref count of 1.
// Assumes that |out_node| is non-NULL.
......
......@@ -57,19 +57,6 @@ void FuseFs::Destroy() {
fuse_ops_->destroy(fuse_user_data_);
}
Error FuseFs::Access(const Path& path, int a_mode) {
if (!fuse_ops_->access) {
LOG_TRACE("fuse_ops_->access is NULL.");
return ENOSYS;
}
int result = fuse_ops_->access(path.Join().c_str(), a_mode);
if (result < 0)
return -result;
return 0;
}
Error FuseFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
std::string path_str = path.Join();
const char* path_cstr = path_str.c_str();
......
......@@ -21,7 +21,6 @@ class FuseFs : public Filesystem {
virtual void Destroy();
public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
......
......@@ -29,12 +29,6 @@ int64_t strtoull(const char* nptr, char** endptr, int base) {
} // namespace
Error Html5Fs::Access(const Path& path, int a_mode) {
// a_mode is unused, since all files are readable, writable and executable.
ScopedNode node;
return Open(path, O_RDONLY, &node);
}
Error Html5Fs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL);
Error error = BlockUntilFilesystemOpen();
......
......@@ -18,7 +18,6 @@ class Node;
class Html5Fs : public Filesystem {
public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
......
......@@ -41,31 +41,6 @@ std::string NormalizeHeaderKey(const std::string& s) {
return result;
}
Error HttpFs::Access(const Path& path, int a_mode) {
ScopedNode node = FindExistingNode(path);
if (node.get() == NULL) {
// If we can't find the node in the cache, fetch it
std::string url = MakeUrl(path);
node.reset(new HttpFsNode(this, url, cache_content_));
Error error = node->Init(0);
if (error)
return error;
error = node->GetStat(NULL);
if (error)
return error;
}
int obj_mode = node->GetMode();
if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) ||
((a_mode & W_OK) && !(obj_mode & S_IWRITE)) ||
((a_mode & X_OK) && !(obj_mode & S_IEXEC))) {
return EACCES;
}
return 0;
}
Error HttpFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL);
......
......@@ -18,7 +18,6 @@ class HttpFs : public Filesystem {
public:
typedef std::map<std::string, ScopedNode> NodeMap_t;
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
......
......@@ -391,19 +391,6 @@ PP_Var JsFs::WaitForResponse(RequestId request_id) {
}
}
Error JsFs::Access(const Path& path, int a_mode) {
ScopedVar response(ppapi_);
if (!SendRequestAndWait(&response, "%s%s%d",
"cmd", "access",
"path", path.Join().c_str(),
"amode", a_mode)) {
LOG_ERROR("Failed to send request.");
return EINVAL;
}
return ErrorFromResponse(response);
}
Error JsFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL);
ScopedVar response(ppapi_);
......
......@@ -35,7 +35,6 @@ class JsFs : public Filesystem {
virtual void Destroy();
public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
......
......@@ -843,20 +843,18 @@ int KernelProxy::fcntl(int fd, int request, va_list args) {
}
int KernelProxy::access(const char* path, int amode) {
ScopedFilesystem fs;
Path rel;
struct stat buf;
int rtn = stat(path, &buf);
if (rtn != 0)
return rtn;
Error error = AcquireFsAndRelPath(path, &fs, &rel);
if (error) {
errno = error;
if (((amode & R_OK) && !(buf.st_mode & S_IREAD)) ||
((amode & W_OK) && !(buf.st_mode & S_IWRITE)) ||
((amode & X_OK) && !(buf.st_mode & S_IEXEC))) {
errno = EACCES;
return -1;
}
error = fs->Access(rel, amode);
if (error) {
errno = error;
return -1;
}
return 0;
}
......
......@@ -75,23 +75,6 @@ Error MemFs::FindNode(const Path& path, int type, ScopedNode* out_node) {
return 0;
}
Error MemFs::Access(const Path& path, int a_mode) {
ScopedNode node;
Error error = FindNode(path, 0, &node);
if (error)
return error;
int obj_mode = node->GetMode();
if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) ||
((a_mode & W_OK) && !(obj_mode & S_IWRITE)) ||
((a_mode & X_OK) && !(obj_mode & S_IEXEC))) {
return EACCES;
}
return 0;
}
Error MemFs::Open(const Path& path, int open_flags, ScopedNode* out_node) {
out_node->reset(NULL);
ScopedNode node;
......
......@@ -29,7 +29,6 @@ class MemFs : public Filesystem {
virtual Error FindNode(const Path& path, int type, ScopedNode* out_node);
public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int perm);
......
......@@ -22,11 +22,6 @@ Error PassthroughFs::Init(const FsInitArgs& args) {
void PassthroughFs::Destroy() {
}
Error PassthroughFs::Access(const Path& path, int a_mode) {
// There is no underlying 'access' syscall in NaCl. It just returns ENOSYS.
return ENOSYS;
}
Error PassthroughFs::Open(const Path& path, int mode, ScopedNode* out_node) {
out_node->reset(NULL);
int real_fd;
......
......@@ -18,7 +18,6 @@ class PassthroughFs : public Filesystem {
virtual void Destroy();
public:
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
virtual Error OpenResource(const Path& path, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
......
......@@ -84,10 +84,6 @@ StreamFs::~StreamFs() {
pthread_cond_destroy(&message_cond_);
}
Error StreamFs::Access(const Path& path, int a_mode) {
return EACCES;
}
Error StreamFs::Open(const Path& path, int o_flags, ScopedNode* out_node) {
return EACCES;
}
......
......@@ -54,7 +54,6 @@ class StreamFs : public Filesystem {
// of a MountSocketWork object.
static PP_CompletionCallback GetRunCompletion(Work* work);
virtual Error Access(const Path& path, int a_mode);
virtual Error Open(const Path& path, int o_flags, ScopedNode* out_node);
virtual Error Unlink(const Path& path);
virtual Error Mkdir(const Path& path, int permissions);
......
......@@ -20,6 +20,15 @@ class DevFsForTesting : public nacl_io::DevFs {
Init(args);
}
bool Exists(const char* filename) {
nacl_io::ScopedNode node;
if (Open(nacl_io::Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
int num_nodes() { return (int)inode_pool_.size(); }
};
......
......@@ -28,6 +28,15 @@ class MemFsForTesting : public MemFs {
EXPECT_EQ(0, Init(args));
}
bool Exists(const char* filename) {
ScopedNode node;
if (Open(Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
int num_nodes() { return (int)inode_pool_.size(); }
};
......@@ -42,13 +51,13 @@ TEST(FilesystemTest, Sanity) {
off_t result_size = 0;
int result_bytes = 0;
struct stat buf;
char buf1[1024];
// A memory filesystem starts with one directory node: the root.
EXPECT_EQ(1, fs.num_nodes());
// Fail to open non existent file
EXPECT_EQ(ENOENT, fs.Access(Path("/foo"), R_OK | W_OK));
EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDWR, &result_node));
EXPECT_EQ(NULL, result_node.get());
EXPECT_EQ(1, fs.num_nodes());
......@@ -59,14 +68,16 @@ TEST(FilesystemTest, Sanity) {
// We now have a directory and a file. The file has a two references
// one returned to the test, one for the name->inode map.
EXPECT_EQ(2, fs.num_nodes());
EXPECT_EQ(2, file->RefCount());
EXPECT_EQ(0, fs.Access(Path("/foo"), R_OK | W_OK));
EXPECT_EQ(EACCES, fs.Access(Path("/foo"), X_OK));
ASSERT_EQ(2, fs.num_nodes());
ASSERT_EQ(2, file->RefCount());
ASSERT_EQ(0, file->GetStat(&buf));
ASSERT_EQ(0, buf.st_mode & S_IXUSR);
// All access should be allowed on the root directory.
EXPECT_EQ(0, fs.Access(Path("/"), R_OK | W_OK | X_OK));
// Open the root directory for write should fail.
EXPECT_EQ(0, fs.Open(Path("/"), O_RDONLY, &root));
ASSERT_EQ(0, root->GetStat(&buf));
ASSERT_EQ(S_IRWXU, buf.st_mode & S_IRWXU);
// Opening a directory for write should fail.
EXPECT_EQ(EISDIR, fs.Open(Path("/"), O_RDWR, &root));
EXPECT_EQ(2, fs.num_nodes());
......@@ -157,8 +168,7 @@ TEST(FilesystemTest, Sanity) {
EXPECT_EQ(1, fs.num_nodes());
// Verify the directory is gone
EXPECT_EQ(ENOENT, fs.Access(Path("/foo"), F_OK));
EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDWR, &file));
EXPECT_EQ(ENOENT, fs.Open(Path("/foo"), O_RDONLY, &file));
EXPECT_EQ(NULL_NODE, file.get());
}
......@@ -213,25 +223,25 @@ TEST(FilesystemTest, MemFsRename) {
ScopedNode file;
ASSERT_EQ(0, fs.Open(Path("/dir1/file"), O_RDWR | O_CREAT | O_EXCL, &file));
ASSERT_EQ(0, fs.Access(Path("/dir1/file"), R_OK));
ASSERT_TRUE(fs.Exists("/dir1/file"));
ASSERT_EQ(4, fs.num_nodes());
// Move from one directory to another should ok
ASSERT_EQ(0, fs.Rename(Path("/dir1/file"), Path("/dir2/new_file")));
ASSERT_NE(0, fs.Access(Path("/dir1/file"), R_OK));
ASSERT_EQ(0, fs.Access(Path("/dir2/new_file"), R_OK));
ASSERT_FALSE(fs.Exists("/dir1/file"));
ASSERT_TRUE(fs.Exists("/dir2/new_file"));
ASSERT_EQ(4, fs.num_nodes());
// Move within the same directory
ASSERT_EQ(0, fs.Rename(Path("/dir2/new_file"), Path("/dir2/new_file2")));
ASSERT_NE(0, fs.Access(Path("/dir2/new_file"), R_OK));
ASSERT_EQ(0, fs.Access(Path("/dir2/new_file2"), R_OK));
ASSERT_FALSE(fs.Exists("/dir2/new_file"));
ASSERT_TRUE(fs.Exists("/dir2/new_file2"));
ASSERT_EQ(4, fs.num_nodes());
// Move to another directory but without a filename
ASSERT_EQ(0, fs.Rename(Path("/dir2/new_file2"), Path("/dir1")));
ASSERT_NE(0, fs.Access(Path("/dir2/new_file2"), R_OK));
ASSERT_EQ(0, fs.Access(Path("/dir1/new_file2"), R_OK));
ASSERT_FALSE(fs.Exists("/dir2/new_file2"));
ASSERT_TRUE(fs.Exists("/dir1/new_file2"));
ASSERT_EQ(4, fs.num_nodes());
}
......@@ -244,8 +254,8 @@ TEST(FilesystemTest, MemFsRenameDir) {
// Renaming one directory to another should work
ASSERT_EQ(0, fs.Rename(Path("/dir1"), Path("/dir2")));
ASSERT_NE(0, fs.Access(Path("/dir1"), R_OK));
ASSERT_EQ(0, fs.Access(Path("/dir2"), R_OK));
ASSERT_FALSE(fs.Exists("/dir1"));
ASSERT_TRUE(fs.Exists("/dir2"));
EXPECT_EQ(2, fs.num_nodes());
// Reset to initial state
......@@ -254,8 +264,8 @@ TEST(FilesystemTest, MemFsRenameDir) {
// Renaming a directory to a new name within another
ASSERT_EQ(0, fs.Rename(Path("/dir1"), Path("/dir2/foo")));
ASSERT_EQ(0, fs.Access(Path("/dir2"), R_OK));
ASSERT_EQ(0, fs.Access(Path("/dir2/foo"), R_OK));
ASSERT_TRUE(fs.Exists("/dir2"));
ASSERT_TRUE(fs.Exists("/dir2/foo"));
EXPECT_EQ(3, fs.num_nodes());
// Reset to initial state
......@@ -273,7 +283,7 @@ TEST(FilesystemTest, DevAccess) {
FakePepperInterface pepper;
DevFsForTesting fs(&pepper);
ScopedNode invalid_node, valid_node;
ASSERT_EQ(ENOENT, fs.Access(Path("/foo"), F_OK));
ASSERT_FALSE(fs.Exists("/foo"));
// Creating non-existent file should return EACCES
ASSERT_EQ(EACCES, fs.Open(Path("/foo"), O_CREAT | O_RDWR, &invalid_node));
......@@ -295,11 +305,12 @@ TEST(FilesystemTest, DevNull) {
DevFsForTesting fs(&pepper);
ScopedNode dev_null;
int result_bytes = 0;
struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/null"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/null"), X_OK));
ASSERT_EQ(0, fs.Open(Path("/null"), O_RDWR, &dev_null));
ASSERT_NE(NULL_NODE, dev_null.get());
ASSERT_EQ(0, dev_null->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
// Writing to /dev/null should write everything.
const char msg[] = "Dummy test message.";
......@@ -319,11 +330,12 @@ TEST(FilesystemTest, DevZero) {
DevFsForTesting fs(&pepper);
ScopedNode dev_zero;
int result_bytes = 0;
struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/zero"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/zero"), X_OK));
ASSERT_EQ(0, fs.Open(Path("/zero"), O_RDWR, &dev_zero));
ASSERT_NE(NULL_NODE, dev_zero.get());
ASSERT_EQ(0, dev_zero->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
// Writing to /dev/zero should write everything.
HandleAttr attrs;
......@@ -350,11 +362,12 @@ TEST(FilesystemTest, DISABLED_DevUrandom) {
DevFsForTesting fs(&pepper);
ScopedNode dev_urandom;
int result_bytes = 0;
struct stat buf;
ASSERT_EQ(0, fs.Access(Path("/urandom"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/urandom"), X_OK));
ASSERT_EQ(0, fs.Open(Path("/urandom"), O_RDWR, &dev_urandom));
ASSERT_NE(NULL_NODE, dev_urandom.get());
ASSERT_EQ(0, dev_urandom->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
// Writing to /dev/urandom should write everything.
const char msg[] = "Dummy test message.";
......
......@@ -48,6 +48,15 @@ class Html5FsForTesting : public Html5Fs {
Error error = Init(args);
EXPECT_EQ(expected_error, error);
}
bool Exists(const char* filename) {
ScopedNode node;
if (Open(Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
};
class Html5FsTest : public ::testing::Test {
......@@ -143,7 +152,7 @@ TEST_F(Html5FsTest, PassFilesystemResource) {
ScopedRef<Html5FsForTesting> fs(
new Html5FsForTesting(map, &ppapi_));
ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK));
ASSERT_TRUE(fs->Exists("/foo"));
ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem);
}
......@@ -156,18 +165,8 @@ TEST_F(Html5FsTest, MountSubtree) {
map["SOURCE"] = "/foo";
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
ASSERT_EQ(0, fs->Access(Path("/bar"), R_OK | W_OK | X_OK));
ASSERT_EQ(ENOENT, fs->Access(Path("/foo/bar"), F_OK));
}
TEST_F(Html5FsTest, Access) {
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK));
ASSERT_EQ(ENOENT, fs->Access(Path("/bar"), F_OK));
ASSERT_TRUE(fs->Exists("/bar"));
ASSERT_FALSE(fs->Exists("/foo/bar"));
}
TEST_F(Html5FsTest, Mkdir) {
......@@ -178,7 +177,7 @@ TEST_F(Html5FsTest, Mkdir) {
EXPECT_EQ(EEXIST, fs->Mkdir(Path("/"), 0644));
Path path("/foo");
ASSERT_EQ(ENOENT, fs->Access(path, F_OK));
ASSERT_FALSE(fs->Exists("/foo"));
ASSERT_EQ(0, fs->Mkdir(path, 0644));
struct stat stat;
......@@ -189,15 +188,16 @@ TEST_F(Html5FsTest, Mkdir) {
}
TEST_F(Html5FsTest, Remove) {
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));
const char* kPath = "/foo";
EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile(kPath, NULL));
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
Path path("/foo");
ASSERT_EQ(0, fs->Access(path, F_OK));
Path path(kPath);
ASSERT_TRUE(fs->Exists(kPath));
ASSERT_EQ(0, fs->Remove(path));
EXPECT_EQ(ENOENT, fs->Access(path, F_OK));
EXPECT_FALSE(fs->Exists(kPath));
}
TEST_F(Html5FsTest, Unlink) {
......@@ -207,10 +207,12 @@ TEST_F(Html5FsTest, Unlink) {
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
ASSERT_TRUE(fs->Exists("/dir"));
ASSERT_TRUE(fs->Exists("/file"));
ASSERT_EQ(0, fs->Unlink(Path("/file")));
ASSERT_EQ(EISDIR, fs->Unlink(Path("/dir")));
EXPECT_EQ(0, fs->Unlink(Path("/file")));
EXPECT_EQ(ENOENT, fs->Access(Path("/file"), F_OK));
EXPECT_EQ(0, fs->Access(Path("/dir"), F_OK));
EXPECT_FALSE(fs->Exists("/file"));
EXPECT_TRUE(fs->Exists("/dir"));
}
TEST_F(Html5FsTest, Rmdir) {
......@@ -222,8 +224,8 @@ TEST_F(Html5FsTest, Rmdir) {
ASSERT_EQ(ENOTDIR, fs->Rmdir(Path("/file")));
EXPECT_EQ(0, fs->Rmdir(Path("/dir")));
EXPECT_EQ(ENOENT, fs->Access(Path("/dir"), F_OK));
EXPECT_EQ(0, fs->Access(Path("/file"), F_OK));
EXPECT_FALSE(fs->Exists("/dir"));
EXPECT_TRUE(fs->Exists("/file"));
}
TEST_F(Html5FsTest, Rename) {
......@@ -232,21 +234,19 @@ TEST_F(Html5FsTest, Rename) {
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
Path path("/foo");
Path newpath("/bar");
ASSERT_EQ(0, fs->Access(path, F_OK));
ASSERT_EQ(0, fs->Rename(path, newpath));
EXPECT_EQ(ENOENT, fs->Access(path, F_OK));
EXPECT_EQ(0, fs->Access(newpath, F_OK));
ASSERT_TRUE(fs->Exists("/foo"));
ASSERT_EQ(0, fs->Rename(Path("/foo"), Path("/bar")));
EXPECT_FALSE(fs->Exists("/foo"));
EXPECT_TRUE(fs->Exists("/bar"));
}
TEST_F(Html5FsTest, OpenForCreate) {
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
Path path("/foo");
EXPECT_EQ(ENOENT, fs->Access(path, F_OK));
EXPECT_FALSE(fs->Exists("/foo"));
Path path("/foo");
ScopedNode node;
ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node));
......
......@@ -78,15 +78,6 @@ class HttpFsLargeFileTest : public HttpFsTest {
} // namespace
TEST_P(HttpFsTest, Access) {
ASSERT_TRUE(ppapi_.server_template()->AddEntity("foo", "", NULL));
ASSERT_EQ(0, fs_.Access(Path("/foo"), R_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/foo"), W_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/foo"), X_OK));
ASSERT_EQ(ENOENT, fs_.Access(Path("/bar"), F_OK));
}
TEST_P(HttpFsTest, OpenAndCloseServerError) {
EXPECT_TRUE(ppapi_.server_template()->AddError("file", 500));
......@@ -278,9 +269,9 @@ TEST(HttpFsDirTest, Root) {
ASSERT_TRUE(node->IsaDir());
// We have to r+w access to the root node
ASSERT_EQ(0, fs.Access(Path("/"), R_OK));
ASSERT_EQ(0, fs.Access(Path("/"), X_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK));
struct stat buf;
ASSERT_EQ(0, node->GetStat(&buf));
ASSERT_EQ(S_IXUSR | S_IRUSR, buf.st_mode & S_IRWXU);
}
TEST(HttpFsDirTest, Mkdir) {
......@@ -392,20 +383,17 @@ TEST(HttpFsBlobUrlTest, Basic) {
HttpFsForTesting fs(args, &ppapi);
// Check access to root folder
ASSERT_EQ(0, fs.Access(Path("/"), R_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK));
ASSERT_EQ(EACCES, fs.Access(Path("/"), X_OK));
// Any other path will fail.
ScopedNode foo;
ASSERT_EQ(ENOENT, fs.Access(Path("/blah"), R_OK));
// Verify file size
// Any other path than / should fail.
ScopedNode node;
struct stat statbuf;
ASSERT_EQ(ENOENT, fs.Open(Path("/blah"), R_OK, &node));
// Check access to blob file
ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node));
ASSERT_EQ(0, node->GetStat(&statbuf));
ASSERT_EQ(0, node->GetStat(&statbuf));
ASSERT_EQ(strlen(kContent), statbuf.st_size);
ASSERT_EQ(true, node->IsaFile());
// Verify file size and permissions
struct stat buf;
ASSERT_EQ(0, node->GetStat(&buf));
ASSERT_EQ(S_IRUSR, buf.st_mode & S_IRWXU);
ASSERT_EQ(strlen(kContent), buf.st_size);
}
......@@ -518,27 +518,6 @@ const int JsFsNodeTest::fd = 123;
} // namespace
TEST_F(JsFsTest, Access) {
int a_mode = R_OK | W_OK | X_OK;
PP_Var expected;
ASSERT_EQ(true, CreateDict(&expected));
ASSERT_EQ(true, SetDictKeyValue(&expected, "id", 1));
ASSERT_EQ(true, SetDictKeyValue(&expected, "cmd", "access"));
ASSERT_EQ(true, SetDictKeyValue(&expected, "path", "/foo"));
ASSERT_EQ(true, SetDictKeyValue(&expected, "amode", a_mode));
PP_Var response;
ASSERT_EQ(true, CreateDict(&response));
ASSERT_EQ(true, SetDictKeyValue(&response, "id", 1));
ASSERT_EQ(true, SetDictKeyValue(&response, "error", 0));
Expect(expected, response);
StartJsThread();
EXPECT_EQ(0, fs_->Access(Path("/foo"), a_mode));
}
TEST_F(JsFsTest, Open) {
PP_Var expected;
ASSERT_EQ(true, CreateDict(&expected));
......
......@@ -122,10 +122,11 @@ class JSPipeNodeTest : public ::testing::Test {
void SetUp() {
name_ = "jspipe1";
ASSERT_EQ(0, fs_.Access(Path("/jspipe1"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/jspipe1"), X_OK));
ASSERT_EQ(0, fs_.Open(Path("/jspipe1"), O_RDWR, &pipe_dev_));
ASSERT_NE(NULL_NODE, pipe_dev_.get());
struct stat buf;
ASSERT_EQ(0, pipe_dev_->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
}
/**
......
......@@ -701,7 +701,6 @@ class KernelProxyMMapTest_Node : public Node {
class KernelProxyMMapTest_Filesystem : public Filesystem {
public:
virtual Error Access(const Path& path, int a_mode) { return 0; }
virtual Error Open(const Path& path, int mode, ScopedNode* out_node) {
out_node->reset(new KernelProxyMMapTest_Node(this));
return 0;
......
......@@ -36,6 +36,15 @@ class MemFsForTesting : public MemFs {
EXPECT_EQ(0, Init(args));
}
bool Exists(const char* filename) {
ScopedNode node;
if (Open(Path(filename), O_RDONLY, &node))
return false;
struct stat buf;
return node->GetStat(&buf) == 0;
}
int num_nodes() { return inode_pool_.size(); }
};
......
......@@ -37,10 +37,11 @@ class TtyNodeTest : public ::testing::Test {
TtyNodeTest() : fs_(&ppapi_) {}
void SetUp() {
ASSERT_EQ(0, fs_.Access(Path("/tty"), R_OK | W_OK));
ASSERT_EQ(EACCES, fs_.Access(Path("/tty"), X_OK));
ASSERT_EQ(0, fs_.Open(Path("/tty"), O_RDWR, &dev_tty_));
ASSERT_NE(NULL_NODE, dev_tty_.get());
struct stat buf;
ASSERT_EQ(0, dev_tty_->GetStat(&buf));
ASSERT_EQ(S_IRUSR | S_IWUSR, buf.st_mode & S_IRWXU);
}
protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment