Title: [284124] trunk
Revision
284124
Author
[email protected]
Date
2021-10-13 13:46:48 -0700 (Wed, 13 Oct 2021)

Log Message

Implement FileSystemHandle move()
https://bugs.webkit.org/show_bug.cgi?id=231676
<rdar://problem/84199823>

Reviewed by Youenn Fablet.

Source/WebCore:

Provide a way to move an existing file to a new place in Origin Private File System.

Tests: storage/filesystemaccess/handle-move-worker.html
       storage/filesystemaccess/handle-move.html

* Modules/filesystemaccess/FileSystemHandle.cpp:
(WebCore::FileSystemHandle::move):
* Modules/filesystemaccess/FileSystemHandle.h:
* Modules/filesystemaccess/FileSystemHandle.idl:
* Modules/filesystemaccess/FileSystemStorageConnection.h:
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
(WebCore::WorkerFileSystemStorageConnection::move):
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:

Source/WebKit:

* NetworkProcess/storage/FileSystemStorageHandle.cpp:
(WebKit::isValidFileName):
(WebKit::FileSystemStorageHandle::requestCreateHandle):
(WebKit::FileSystemStorageHandle::removeEntry):
(WebKit::FileSystemStorageHandle::move):
* NetworkProcess/storage/FileSystemStorageHandle.h:
* NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::move):
* NetworkProcess/storage/NetworkStorageManager.h:
* NetworkProcess/storage/NetworkStorageManager.messages.in:
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
(WebKit::WebFileSystemStorageConnection::move):
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h:

LayoutTests:

* storage/filesystemaccess/handle-move-expected.txt: Added.
* storage/filesystemaccess/handle-move-worker-expected.txt: Added.
* storage/filesystemaccess/handle-move-worker.html: Added.
* storage/filesystemaccess/handle-move.html: Added.
* storage/filesystemaccess/resources/handle-move.js: Added.
(finishTest):
(async test):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284123 => 284124)


--- trunk/LayoutTests/ChangeLog	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/LayoutTests/ChangeLog	2021-10-13 20:46:48 UTC (rev 284124)
@@ -1,3 +1,19 @@
+2021-10-13  Sihui Liu  <[email protected]>
+
+        Implement FileSystemHandle move()
+        https://bugs.webkit.org/show_bug.cgi?id=231676
+        <rdar://problem/84199823>
+
+        Reviewed by Youenn Fablet.
+
+        * storage/filesystemaccess/handle-move-expected.txt: Added.
+        * storage/filesystemaccess/handle-move-worker-expected.txt: Added.
+        * storage/filesystemaccess/handle-move-worker.html: Added.
+        * storage/filesystemaccess/handle-move.html: Added.
+        * storage/filesystemaccess/resources/handle-move.js: Added.
+        (finishTest):
+        (async test):
+
 2021-10-13  Fujii Hironori  <[email protected]>
 
         [WinCairo] Unreviewed test gardening

Added: trunk/LayoutTests/storage/filesystemaccess/handle-move-expected.txt (0 => 284124)


--- trunk/LayoutTests/storage/filesystemaccess/handle-move-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/handle-move-expected.txt	2021-10-13 20:46:48 UTC (rev 284124)
@@ -0,0 +1,22 @@
+This test checks move() of FileSystemHandle.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test basic move:
+PASS fileHandle.name is "file"
+PASS fileHandle.name is "newFile"
+PASS getFileHandleError.toString() is "NotFoundError: The object can not be found here."
+PASS fileHandle2.name is "newFile"
+PASS fileHandle2.kind is "file"
+Test move to a file handle:
+PASS moveFileError.toString() is "TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object."
+Test move to a destination with existing file:
+PASS moveFileError.toString() is "UnknownError: The operation failed for an unknown transient reason (e.g. out of memory)."
+Test move with an invalid name:
+PASS moveFileError.toString() is "UnknownError: Name is invalid"
+PASS moveFileError.toString() is "UnknownError: Name is invalid"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/storage/filesystemaccess/handle-move-worker-expected.txt (0 => 284124)


--- trunk/LayoutTests/storage/filesystemaccess/handle-move-worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/handle-move-worker-expected.txt	2021-10-13 20:46:48 UTC (rev 284124)
@@ -0,0 +1,25 @@
+[Worker] This test checks move() of FileSystemHandle.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/handle-move.js
+[Worker] Test basic move:
+PASS [Worker] fileHandle.name is "file"
+PASS [Worker] fileHandle.name is "newFile"
+PASS [Worker] getFileHandleError.toString() is "NotFoundError: The object can not be found here."
+PASS [Worker] fileHandle2.name is "newFile"
+PASS [Worker] fileHandle2.kind is "file"
+[Worker] Test move to a file handle:
+PASS [Worker] moveFileError.toString() is "TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object."
+[Worker] Test move to a destination with existing file:
+PASS [Worker] moveFileError.toString() is "UnknownError: The operation failed for an unknown transient reason (e.g. out of memory)."
+[Worker] Test move with an invalid name:
+PASS [Worker] moveFileError.toString() is "UnknownError: Name is invalid"
+PASS [Worker] moveFileError.toString() is "UnknownError: Name is invalid"
+[Worker] Test move with open access handle:
+PASS [Worker] moveFileError.toString() is "InvalidStateError: The object is in an invalid state."
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/storage/filesystemaccess/handle-move-worker.html (0 => 284124)


--- trunk/LayoutTests/storage/filesystemaccess/handle-move-worker.html	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/handle-move-worker.html	2021-10-13 20:46:48 UTC (rev 284124)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+worker = startWorker('resources/handle-move.js');</script>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/storage/filesystemaccess/handle-move.html (0 => 284124)


--- trunk/LayoutTests/storage/filesystemaccess/handle-move.html	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/handle-move.html	2021-10-13 20:46:48 UTC (rev 284124)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+var jsTestIsAsync = true;
+
+if (!window.testRunner) {
+    finishTest("window.testRunner is not available");
+}
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/storage/filesystemaccess/resources/handle-move.js (0 => 284124)


--- trunk/LayoutTests/storage/filesystemaccess/resources/handle-move.js	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/resources/handle-move.js	2021-10-13 20:46:48 UTC (rev 284124)
@@ -0,0 +1,124 @@
+if (this.importScripts) {
+    importScripts('../../../resources/js-test.js');
+}
+
+description("This test checks move() of FileSystemHandle.");
+
+var rootHandle, dirHandle1, dirHandle2, fileHandle, fileHandle2, testError, getFileHandleError, moveFileError;
+
+function finishTest(error)
+{
+    if (error) {
+        testFailed(error);
+    }
+    finishJSTest();
+}
+
+async function test() {
+    try {
+        var rootHandle = await navigator.storage.getDirectory();
+        // Create two new folders for this test.
+        await rootHandle.removeEntry("dir1", { "recursive" : true }).then(() => { }, () => { });
+        await rootHandle.removeEntry("dir2", { "recursive" : true }).then(() => { }, () => { });
+        dirHandle1 = await rootHandle.getDirectoryHandle("dir1", { "create" : true });
+        dirHandle2 = await rootHandle.getDirectoryHandle("dir2", { "create" : true });
+
+        debug("Test basic move:")
+        fileHandle = await dirHandle1.getFileHandle("file", { "create" : true });
+        shouldBeEqualToString("fileHandle.name", "file");
+        await fileHandle.move(dirHandle2, "newFile");
+        shouldBeEqualToString("fileHandle.name", "newFile");
+
+        testError = null;
+        await dirHandle1.getFileHandle("file", { "create" : false }).then((handle) => {
+            testError = "Got file handle from dirHandle1 unexpectedly"
+        }, (error) => {
+            getFileHandleError = error;
+            shouldBeEqualToString("getFileHandleError.toString()", "NotFoundError: The object can not be found here.");
+        });
+
+        if (testError) {
+            return finishTest(testError);
+        }
+
+        fileHandle2 = await dirHandle2.getFileHandle("newFile", { "create" : false });
+        shouldBeEqualToString("fileHandle2.name", "newFile");
+        shouldBeEqualToString("fileHandle2.kind", "file");
+
+        debug("Test move to a file handle:");
+        testError = null;
+        fileHandle3 = await dirHandle1.getFileHandle("secondFile", { "create" : true });
+        await fileHandle.move(fileHandle3, fileHandle.name).then(() => {
+            testError =  "Moved file to fileHandle3 unexpectedly"
+        }, (error) => {
+            moveFileError = error;
+            shouldBeEqualToString("moveFileError.toString()", "TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object.");
+        });
+
+        if (testError) {
+            return finishTest(testError);
+        }
+
+        debug("Test move to a destination with existing file:");
+        testError = null;
+        await fileHandle.move(dirHandle1, "secondFile").then(() => {
+            testError =  "Moved file to dirHandle1 unexpectedly";
+        }, (error) => {
+            moveFileError = error;
+            shouldBeEqualToString("moveFileError.toString()", "UnknownError: The operation failed for an unknown transient reason (e.g. out of memory).");
+        });
+
+        if (testError) {
+            return finishTest(testError);
+        }
+
+        debug("Test move with an invalid name:");
+        testError = null;
+        await fileHandle.move(dirHandle1, "..").then(() => {
+            testError =  "Moved file to dirHandle1 with invalid name unexpectedly";
+        }, (error) => {
+            moveFileError = error;
+            shouldBeEqualToString("moveFileError.toString()", "UnknownError: Name is invalid");
+        });
+
+        if (testError) {
+            return finishTest(testError);
+        }
+
+        await fileHandle.move(dirHandle1, "root/file").then(() => {
+            testError =  "Moved file to dirHandle1 with invalid name unexpectedly";
+        }, (error) => {
+            moveFileError = error;
+            shouldBeEqualToString("moveFileError.toString()", "UnknownError: Name is invalid");
+        });
+
+        if (testError) {
+            return finishTest(testError);
+        }
+
+
+        if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
+            debug("Test move with open access handle:");
+            testError = null;
+            accessHandle = await fileHandle.createSyncAccessHandle();
+            await fileHandle.move(dirHandle1, "file").then(() => {
+                testError =  "Moved file back to dirHandle1 unexpectedly";
+            }, (error) => {
+                moveFileError = error;
+                shouldBeEqualToString("moveFileError.toString()", "InvalidStateError: The object is in an invalid state.");
+            });
+
+            if (testError) {
+                return finishTest(testError);
+            }
+
+            accessHandle.close();
+        }
+
+        finishTest();
+    } catch (error) {
+        finishTest(error);
+    }
+}
+
+test();

Modified: trunk/Source/WebCore/ChangeLog (284123 => 284124)


--- trunk/Source/WebCore/ChangeLog	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/ChangeLog	2021-10-13 20:46:48 UTC (rev 284124)
@@ -1,3 +1,25 @@
+2021-10-13  Sihui Liu  <[email protected]>
+
+        Implement FileSystemHandle move()
+        https://bugs.webkit.org/show_bug.cgi?id=231676
+        <rdar://problem/84199823>
+
+        Reviewed by Youenn Fablet.
+
+        Provide a way to move an existing file to a new place in Origin Private File System.
+
+        Tests: storage/filesystemaccess/handle-move-worker.html
+               storage/filesystemaccess/handle-move.html
+
+        * Modules/filesystemaccess/FileSystemHandle.cpp:
+        (WebCore::FileSystemHandle::move):
+        * Modules/filesystemaccess/FileSystemHandle.h:
+        * Modules/filesystemaccess/FileSystemHandle.idl:
+        * Modules/filesystemaccess/FileSystemStorageConnection.h:
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
+        (WebCore::WorkerFileSystemStorageConnection::move):
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
+
 2021-10-13  Gabriel Nava Marino  <[email protected]>
 
         Skip fallbackFontsForRunWithIterator for empty runs

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp (284123 => 284124)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp	2021-10-13 20:46:48 UTC (rev 284124)
@@ -54,4 +54,17 @@
     });
 }
 
+void FileSystemHandle::move(FileSystemHandle& destinationHandle, const String& newName, DOMPromiseDeferred<void>&& promise)
+{
+    if (destinationHandle.kind() != Kind::Directory)
+        return promise.reject(Exception { TypeMismatchError });
+
+    m_connection->move(m_identifier, destinationHandle.identifier(), newName, [this, protectedThis = Ref { *this }, newName, promise = WTFMove(promise)](auto result) mutable {
+        if (!result.hasException())
+            m_name = newName;
+
+        promise.settle(WTFMove(result));
+    });
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h (284123 => 284124)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h	2021-10-13 20:46:48 UTC (rev 284124)
@@ -34,7 +34,6 @@
 template<typename> class DOMPromiseDeferred;
 
 class FileSystemStorageConnection;
-enum class PermissionState : uint8_t;
 
 class FileSystemHandle : public RefCounted<FileSystemHandle> {
     WTF_MAKE_ISO_ALLOCATED(FileSystemHandle);
@@ -50,6 +49,7 @@
     FileSystemHandleIdentifier identifier() const { return m_identifier; }
 
     void isSameEntry(FileSystemHandle&, DOMPromiseDeferred<IDLBoolean>&&) const;
+    void move(FileSystemHandle&, const String& newName, DOMPromiseDeferred<void>&&);
 
 protected:
     FileSystemHandle(Kind, String&& name, FileSystemHandleIdentifier, Ref<FileSystemStorageConnection>&&);

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.idl (284123 => 284124)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.idl	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.idl	2021-10-13 20:46:48 UTC (rev 284124)
@@ -38,4 +38,5 @@
     readonly attribute USVString name;
 
     Promise<boolean> isSameEntry(FileSystemHandle other);
+    Promise<undefined> move(FileSystemHandle destination, USVString newName);
 };

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h (284123 => 284124)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h	2021-10-13 20:46:48 UTC (rev 284124)
@@ -51,6 +51,7 @@
     using GetHandleWithTypeCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemHandleIdentifier, bool>>&&)>;
 
     virtual void isSameEntry(FileSystemHandleIdentifier, FileSystemHandleIdentifier, SameEntryCallback&&) = 0;
+    virtual void move(FileSystemHandleIdentifier, FileSystemHandleIdentifier, const String& newName, VoidCallback&&) = 0;
     virtual void getFileHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, GetHandleCallback&&) = 0;
     virtual void getDirectoryHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, GetHandleCallback&&) = 0;
     virtual void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, VoidCallback&&) = 0;

Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp (284123 => 284124)


--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp	2021-10-13 20:46:48 UTC (rev 284124)
@@ -366,4 +366,24 @@
         callback(WTFMove(result));
 }
 
+void WorkerFileSystemStorageConnection::move(FileSystemHandleIdentifier identifier, FileSystemHandleIdentifier destinationIdentifier, const String& newName, VoidCallback&& callback)
+{
+    if (!m_scope)
+        return callback(Exception { InvalidStateError });
+
+    auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
+    m_voidCallbacks.add(callbackIdentifier, WTFMove(callback));
+
+    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, destinationIdentifier, name = crossThreadCopy(newName)]() mutable {
+        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
+                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
+                    connection->completeVoidCallback(callbackIdentifier, WTFMove(result));
+            }, WorkerRunLoop::defaultMode());
+        };
+
+        mainThreadConnection->move(identifier, destinationIdentifier, name, WTFMove(mainThreadCallback));
+    });
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h (284123 => 284124)


--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h	2021-10-13 20:46:48 UTC (rev 284124)
@@ -58,6 +58,7 @@
 
     // FileSystemStorageConnection
     void isSameEntry(FileSystemHandleIdentifier, FileSystemHandleIdentifier, FileSystemStorageConnection::SameEntryCallback&&) final;
+    void move(FileSystemHandleIdentifier, FileSystemHandleIdentifier, const String& newName, VoidCallback&&) final;
     void getFileHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, FileSystemStorageConnection::GetHandleCallback&&) final;
     void getDirectoryHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, FileSystemStorageConnection::GetHandleCallback&&) final;
     void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, FileSystemStorageConnection::VoidCallback&&) final;

Modified: trunk/Source/WebKit/ChangeLog (284123 => 284124)


--- trunk/Source/WebKit/ChangeLog	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/ChangeLog	2021-10-13 20:46:48 UTC (rev 284124)
@@ -1,3 +1,25 @@
+2021-10-13  Sihui Liu  <[email protected]>
+
+        Implement FileSystemHandle move()
+        https://bugs.webkit.org/show_bug.cgi?id=231676
+        <rdar://problem/84199823>
+
+        Reviewed by Youenn Fablet.
+
+        * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+        (WebKit::isValidFileName):
+        (WebKit::FileSystemStorageHandle::requestCreateHandle):
+        (WebKit::FileSystemStorageHandle::removeEntry):
+        (WebKit::FileSystemStorageHandle::move):
+        * NetworkProcess/storage/FileSystemStorageHandle.h:
+        * NetworkProcess/storage/NetworkStorageManager.cpp:
+        (WebKit::NetworkStorageManager::move):
+        * NetworkProcess/storage/NetworkStorageManager.h:
+        * NetworkProcess/storage/NetworkStorageManager.messages.in:
+        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
+        (WebKit::WebFileSystemStorageConnection::move):
+        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h:
+
 2021-10-13  Wenson Hsieh  <[email protected]>
 
         Support both VK and VKC-prefixed SPI when softlinking VisionKitCore classes

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (284123 => 284124)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp	2021-10-13 20:46:48 UTC (rev 284124)
@@ -72,6 +72,11 @@
     return m_path == path;
 }
 
+static bool isValidFileName(const String& name)
+{
+    return name != "." && name != ".." && !name.contains(pathSeparator);
+}
+
 Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> FileSystemStorageHandle::requestCreateHandle(IPC::Connection::UniqueID connection, Type type, String&& name, bool createIfNecessary)
 {
     if (m_type != FileSystemStorageHandle::Type::Directory)
@@ -81,7 +86,7 @@
         return makeUnexpected(FileSystemStorageError::Unknown);
 
     // https://wicg.github.io/file-system-access/#valid-file-name
-    if (name == "." || name == ".." || name.contains(pathSeparator))
+    if (!isValidFileName(name))
         return makeUnexpected(FileSystemStorageError::InvalidName);
 
     auto path = FileSystem::pathByAppendingComponent(m_path, name);
@@ -254,4 +259,36 @@
     return std::pair { result.value(), resultType == FileSystemStorageHandle::Type::Directory };
 }
 
+std::optional<FileSystemStorageError> FileSystemStorageHandle::move(WebCore::FileSystemHandleIdentifier destinationIdentifier, const String& newName)
+{
+    if (!m_manager)
+        return FileSystemStorageError::Unknown;
+
+    // Do not move file if there is ongoing operation.
+    if (m_activeSyncAccessHandle)
+        return FileSystemStorageError::InvalidState;
+
+    if (m_manager->getType(destinationIdentifier) != Type::Directory)
+        return FileSystemStorageError::TypeMismatch;
+
+    auto path = m_manager->getPath(destinationIdentifier);
+    if (path.isEmpty())
+        return FileSystemStorageError::Unknown;
+
+    if (!isValidFileName(newName))
+        return FileSystemStorageError::InvalidName;
+
+    auto destinationPath = FileSystem::pathByAppendingComponent(path, newName);
+    if (FileSystem::fileExists(destinationPath))
+        return FileSystemStorageError::Unknown;
+
+    if (!FileSystem::moveFile(m_path, destinationPath))
+        return FileSystemStorageError::Unknown;
+
+    m_path = destinationPath;
+    m_name = newName;
+
+    return std::nullopt;
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (284123 => 284124)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h	2021-10-13 20:46:48 UTC (rev 284124)
@@ -50,6 +50,7 @@
     Type type() const { return m_type; }
 
     bool isSameEntry(WebCore::FileSystemHandleIdentifier);
+    std::optional<FileSystemStorageError> move(WebCore::FileSystemHandleIdentifier, const String& newName);
     Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> getFileHandle(IPC::Connection::UniqueID, String&& name, bool createIfNecessary);
     Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> getDirectoryHandle(IPC::Connection::UniqueID, String&& name, bool createIfNecessary);
     std::optional<FileSystemStorageError> removeEntry(const String& name, bool deleteRecursively);

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (284123 => 284124)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2021-10-13 20:46:48 UTC (rev 284124)
@@ -182,6 +182,17 @@
     completionHandler(handle->isSameEntry(targetIdentifier));
 }
 
+void NetworkStorageManager::move(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier destinationIdentifier, const String& newName, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    auto handle = m_fileSystemStorageHandleRegistry->getHandle(identifier);
+    if (!handle)
+        return completionHandler(FileSystemStorageError::Unknown);
+
+    completionHandler(handle->move(destinationIdentifier, newName));
+}
+
 void NetworkStorageManager::getFileHandle(IPC::Connection& connection, WebCore::FileSystemHandleIdentifier identifier, String&& name, bool createIfNecessary, CompletionHandler<void(Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError>)>&& completionHandler)
 {
     ASSERT(!RunLoop::isMain());

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h (284123 => 284124)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h	2021-10-13 20:46:48 UTC (rev 284124)
@@ -70,10 +70,12 @@
     void persist(const WebCore::ClientOrigin&, CompletionHandler<void(bool)>&&);
     void fileSystemGetDirectory(IPC::Connection&, const WebCore::ClientOrigin&, CompletionHandler<void(Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError>)>&&);
     void isSameEntry(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, CompletionHandler<void(bool)>&&);
+    void move(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, const String& newName, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
     void getFileHandle(IPC::Connection&, WebCore::FileSystemHandleIdentifier, String&& name, bool createIfNecessary, CompletionHandler<void(Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError>)>&&);
     void getDirectoryHandle(IPC::Connection&, WebCore::FileSystemHandleIdentifier, String&& name, bool createIfNecessary, CompletionHandler<void(Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError>)>&&);
     void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
     void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<Vector<String>, FileSystemStorageError>)>&&);
+
     using AccessHandleInfo = std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>;
     void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<AccessHandleInfo, FileSystemStorageError>)>&&);
     void getSizeForAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(Expected<uint64_t, FileSystemStorageError>)>&&);

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in (284123 => 284124)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in	2021-10-13 20:46:48 UTC (rev 284124)
@@ -32,6 +32,7 @@
     GetDirectoryHandle(WebCore::FileSystemHandleIdentifier identifier, String name, bool createIfNecessary) -> (Expected<WebCore::FileSystemHandleIdentifier, WebKit::FileSystemStorageError> result) Async WantsConnection
     RemoveEntry(WebCore::FileSystemHandleIdentifier identifier, String name, bool deleteRecursively) -> (std::optional<WebKit::FileSystemStorageError> result) Async
     Resolve(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier targetIdentifier) -> (Expected<Vector<String>, WebKit::FileSystemStorageError> result) Async
+    Move(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier destinationIdentifier, String newName) -> (std::optional<WebKit::FileSystemStorageError> result) Async
 
     CreateSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>, WebKit::FileSystemStorageError> result) Async
     GetSizeForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (Expected<uint64_t, WebKit::FileSystemStorageError> result) Async

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp (284123 => 284124)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp	2021-10-13 20:46:48 UTC (rev 284124)
@@ -195,4 +195,14 @@
     });
 }
 
+void WebFileSystemStorageConnection::move(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier destinationIdentifier, const String& newName, VoidCallback&& completionHandler)
+{
+    if (!m_connection)
+        return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
+
+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::Move(identifier, destinationIdentifier, newName), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
+        completionHandler(convertToExceptionOr(error));
+    });
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h (284123 => 284124)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h	2021-10-13 20:46:02 UTC (rev 284123)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h	2021-10-13 20:46:48 UTC (rev 284124)
@@ -72,13 +72,14 @@
     explicit WebFileSystemStorageConnection(IPC::Connection&);
 
     // FileSystemStorageConnection
-    void isSameEntry(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::SameEntryCallback&&);
-    void getFileHandle(WebCore::FileSystemHandleIdentifier, const String& name, bool createIfNecessary, WebCore::FileSystemStorageConnection::GetHandleCallback&&);
-    void getDirectoryHandle(WebCore::FileSystemHandleIdentifier, const String& name, bool createIfNecessary, WebCore::FileSystemStorageConnection::GetHandleCallback&&);
-    void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::VoidCallback&&);
-    void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::ResolveCallback&&);
-    void getHandleNames(WebCore::FileSystemHandleIdentifier, FileSystemStorageConnection::GetHandleNamesCallback&&);
-    void getHandle(WebCore::FileSystemHandleIdentifier, const String& name, FileSystemStorageConnection::GetHandleWithTypeCallback&&);
+    void isSameEntry(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::SameEntryCallback&&) final;
+    void move(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, const String& newName, VoidCallback&&) final;
+    void getFileHandle(WebCore::FileSystemHandleIdentifier, const String& name, bool createIfNecessary, WebCore::FileSystemStorageConnection::GetHandleCallback&&) final;
+    void getDirectoryHandle(WebCore::FileSystemHandleIdentifier, const String& name, bool createIfNecessary, WebCore::FileSystemStorageConnection::GetHandleCallback&&) final;
+    void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
+    void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::ResolveCallback&&) final;
+    void getHandleNames(WebCore::FileSystemHandleIdentifier, FileSystemStorageConnection::GetHandleNamesCallback&&) final;
+    void getHandle(WebCore::FileSystemHandleIdentifier, const String& name, FileSystemStorageConnection::GetHandleWithTypeCallback&&) final;
 
     void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::GetAccessHandleCallback&&) final;
     void getSize(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::FileSystemStorageConnection::IntegerCallback&&) final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to