summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 09:10:29 +0000
committerhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 09:10:29 +0000
commit1e7e41e75151197f026df35b9c01c4bc63bccef0 (patch)
tree591fb018cd68d016452c3e9153ed353be8ee64da
parent6ee05a5b3e33668d67deb9a000ba5d32b3104c7a (diff)
downloadchromium_src-1e7e41e75151197f026df35b9c01c4bc63bccef0.zip
chromium_src-1e7e41e75151197f026df35b9c01c4bc63bccef0.tar.gz
chromium_src-1e7e41e75151197f026df35b9c01c4bc63bccef0.tar.bz2
Implement rename for HTML5 File System
This enables mv command in naclports. TEST=./build_tools/test_sdk.py Review URL: https://codereview.chromium.org/150343004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248940 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc15
-rw-r--r--native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h2
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc32
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h5
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc14
5 files changed, 67 insertions, 1 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
index 64a1f47..fdee818 100644
--- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
+++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs.cc
@@ -117,7 +117,20 @@ Error Html5Fs::Rename(const Path& path, const Path& newpath) {
if (!fileref_resource.pp_resource())
return ENOENT;
- return EACCES;
+ ScopedResource new_fileref_resource(
+ ppapi(),
+ ppapi()->GetFileRefInterface()->Create(filesystem_resource_,
+ newpath.Join().c_str()));
+ if (!new_fileref_resource.pp_resource())
+ return ENOENT;
+
+ int32_t result = ppapi()->GetFileRefInterface()->Rename(
+ fileref_resource.pp_resource(), new_fileref_resource.pp_resource(),
+ PP_BlockUntilComplete());
+ if (result != PP_OK)
+ return PPErrorToErrno(result);
+
+ return 0;
}
Html5Fs::Html5Fs()
diff --git a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
index 4bbd40a..527e68e 100644
--- a/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
+++ b/native_client_sdk/src/libraries/nacl_io/pepper/all_interfaces.h
@@ -57,6 +57,8 @@ BEGIN_INTERFACE(FileRefInterface, PPB_FileRef_1_2, PPB_FILEREF_INTERFACE_1_2)
PP_CompletionCallback)
METHOD3(FileRefInterface, int32_t, ReadDirectoryEntries, PP_Resource,
const PP_ArrayOutput&, PP_CompletionCallback)
+ METHOD3(FileRefInterface, int32_t, Rename, PP_Resource, PP_Resource,
+ PP_CompletionCallback)
END_INTERFACE(FileRefInterface, PPB_FileRef_1_2)
BEGIN_INTERFACE(FileSystemInterface, PPB_FileSystem_1_0,
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc
index 73549658..7577ac8 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.cc
@@ -622,6 +622,38 @@ int32_t FakeFileRefInterface::ReadDirectoryEntries(
return RunCompletionCallback(&callback, PP_OK);
}
+int32_t FakeFileRefInterface::Rename(PP_Resource file_ref,
+ PP_Resource new_file_ref,
+ PP_CompletionCallback callback) {
+ FakeFileRefResource* file_ref_resource =
+ core_interface_->resource_manager()->Get<FakeFileRefResource>(file_ref);
+ if (file_ref_resource == NULL)
+ return PP_ERROR_BADRESOURCE;
+
+ FakeFileRefResource* new_file_ref_resource =
+ core_interface_->resource_manager()->Get<FakeFileRefResource>(
+ new_file_ref);
+ if (new_file_ref_resource == NULL)
+ return PP_ERROR_BADRESOURCE;
+
+ FakeHtml5FsFilesystem* filesystem = file_ref_resource->filesystem;
+ FakeHtml5FsFilesystem::Path path = file_ref_resource->path;
+ FakeHtml5FsFilesystem::Path newpath = new_file_ref_resource->path;
+ FakeHtml5FsNode* node = filesystem->GetNode(path);
+ if (node == NULL)
+ return RunCompletionCallback(&callback, PP_ERROR_FILENOTFOUND);
+ // FakeFileRefResource does not support directory rename.
+ if (!node->IsRegular())
+ return RunCompletionCallback(&callback, PP_ERROR_NOTAFILE);
+
+ // Remove the destination if it exists.
+ filesystem->RemoveNode(newpath);
+ const std::vector<uint8_t> contents = node->contents();
+ EXPECT_TRUE(filesystem->AddFile(newpath, contents, NULL));
+ EXPECT_TRUE(filesystem->RemoveNode(path));
+ return RunCompletionCallback(&callback, PP_OK);
+}
+
FakeFileSystemInterface::FakeFileSystemInterface(
FakeCoreInterface* core_interface)
: core_interface_(core_interface) {}
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h
index 2effa6c..81f68bf 100644
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h
@@ -52,6 +52,8 @@ class FakeHtml5FsNode {
void set_last_access_time(PP_Time time) { info_.last_access_time = time; }
void set_last_modified_time(PP_Time time) { info_.last_modified_time = time; }
+ const std::vector<uint8_t>& contents() const { return contents_; }
+
private:
PP_FileInfo info_;
std::vector<uint8_t> contents_;
@@ -146,6 +148,9 @@ class FakeFileRefInterface : public nacl_io::FileRefInterface {
virtual int32_t ReadDirectoryEntries(PP_Resource file_ref,
const PP_ArrayOutput& output,
PP_CompletionCallback callback);
+ virtual int32_t Rename(PP_Resource file_ref,
+ PP_Resource new_file_ref,
+ PP_CompletionCallback callback);
private:
FakeCoreInterface* core_interface_; // Weak reference.
diff --git a/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc b/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc
index c91eeaf..9a73b73 100644
--- a/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc
@@ -188,6 +188,20 @@ TEST_F(Html5FsTest, DISABLED_Rmdir) {
EXPECT_EQ(0, fs->Access(Path("/file"), F_OK));
}
+TEST_F(Html5FsTest, Rename) {
+ EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));
+
+ 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));
+}
+
TEST_F(Html5FsTest, OpenForCreate) {
StringMap_t map;
ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));