Bug 1818718 - Send and update new EntryId to handle after moves. r=dom-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D174392
This commit is contained in:
Jari Jalkanen 2023-06-08 11:50:30 +00:00
Родитель e6e9cdf594
Коммит 5e1c84ec68
10 изменённых файлов: 97 добавлений и 90 удалений

Просмотреть файл

@ -167,16 +167,15 @@ already_AddRefed<Promise> FileSystemHandle::Move(const fs::EntryId& aParentId,
return nullptr;
}
fs::Name name(aName);
fs::FileSystemChildMetadata newMetadata;
newMetadata.parentId() = aParentId;
newMetadata.childName() = aName;
if (!aParentId.IsEmpty()) {
fs::FileSystemChildMetadata newMetadata;
newMetadata.parentId() = aParentId;
newMetadata.childName() = aName;
mRequestHandler->MoveEntry(mManager, this, mMetadata, newMetadata, promise,
mRequestHandler->MoveEntry(mManager, this, &mMetadata, newMetadata, promise,
aError);
} else {
mRequestHandler->RenameEntry(mManager, this, mMetadata, name, promise,
aError);
mRequestHandler->RenameEntry(mManager, this, &mMetadata,
newMetadata.childName(), promise, aError);
}
if (aError.Failed()) {
return nullptr;
@ -185,13 +184,13 @@ already_AddRefed<Promise> FileSystemHandle::Move(const fs::EntryId& aParentId,
// Other handles to this will be broken, and the spec is ok with this, but we
// need to update our EntryId and name
promise->AddCallbacksWithCycleCollectedArgs(
[name](JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv,
FileSystemHandle* aHandle) {
[newMetadata](JSContext* aCx, JS::Handle<JS::Value> aValue,
ErrorResult& aRv, FileSystemHandle* aHandle) {
// XXX Fix entryId!
LOG(("Changing FileSystemHandle name from %s to %s",
NS_ConvertUTF16toUTF8(aHandle->mMetadata.entryName()).get(),
NS_ConvertUTF16toUTF8(name).get()));
aHandle->mMetadata.entryName() = name;
NS_ConvertUTF16toUTF8(newMetadata.childName()).get()));
aHandle->mMetadata.entryName() = newMetadata.childName();
},
[](JSContext* aCx, JS::Handle<JS::Value> aValue, ErrorResult& aRv,
FileSystemHandle* aHandle) {

Просмотреть файл

@ -197,16 +197,23 @@ void ResolveCallback(
template <>
void ResolveCallback(
FileSystemMoveEntryResponse&& aResponse,
RefPtr<Promise> aPromise) { // NOLINT(performance-unnecessary-value-param)
RefPtr<Promise> aPromise, // NOLINT(performance-unnecessary-value-param)
FileSystemEntryMetadata* const& aEntry, const Name& aName) {
MOZ_ASSERT(aPromise);
QM_TRY(OkIf(Promise::PromiseState::Pending == aPromise->State()), QM_VOID);
MOZ_ASSERT(FileSystemMoveEntryResponse::Tnsresult == aResponse.type());
const auto& status = aResponse.get_nsresult();
if (NS_OK == status) {
if (FileSystemMoveEntryResponse::TEntryId == aResponse.type()) {
if (aEntry) {
aEntry->entryId() = std::move(aResponse.get_EntryId());
aEntry->entryName() = aName;
}
aPromise->MaybeResolveWithUndefined();
return;
}
MOZ_ASSERT(FileSystemMoveEntryResponse::Tnsresult == aResponse.type());
const auto& status = aResponse.get_nsresult();
MOZ_ASSERT(NS_FAILED(status));
HandleFailedStatus(status, aPromise);
}
@ -591,10 +598,12 @@ void FileSystemRequestHandler::RemoveEntry(
void FileSystemRequestHandler::MoveEntry(
RefPtr<FileSystemManager>& aManager, FileSystemHandle* aHandle,
const FileSystemEntryMetadata& aEntry,
FileSystemEntryMetadata* const aEntry,
const FileSystemChildMetadata& aNewEntry,
RefPtr<Promise> aPromise, // NOLINT(performance-unnecessary-value-param)
ErrorResult& aError) {
MOZ_ASSERT(aEntry);
MOZ_ASSERT(!aEntry->entryId().IsEmpty());
MOZ_ASSERT(aPromise);
LOG(("MoveEntry"));
@ -610,9 +619,9 @@ void FileSystemRequestHandler::MoveEntry(
}
aManager->BeginRequest(
[request = FileSystemMoveEntryRequest(aEntry, aNewEntry),
onResolve =
SelectResolveCallback<FileSystemMoveEntryResponse, void>(aPromise),
[request = FileSystemMoveEntryRequest(*aEntry, aNewEntry),
onResolve = SelectResolveCallback<FileSystemMoveEntryResponse, void>(
aPromise, aEntry, aNewEntry.childName()),
onReject = GetRejectCallback(aPromise)](const auto& actor) mutable {
actor->SendMoveEntry(request, std::move(onResolve),
std::move(onReject));
@ -622,10 +631,11 @@ void FileSystemRequestHandler::MoveEntry(
void FileSystemRequestHandler::RenameEntry(
RefPtr<FileSystemManager>& aManager, FileSystemHandle* aHandle,
const FileSystemEntryMetadata& aEntry, const Name& aName,
FileSystemEntryMetadata* const aEntry, const Name& aName,
RefPtr<Promise> aPromise, // NOLINT(performance-unnecessary-value-param)
ErrorResult& aError) {
MOZ_ASSERT(!aEntry.entryId().IsEmpty());
MOZ_ASSERT(aEntry);
MOZ_ASSERT(!aEntry->entryId().IsEmpty());
MOZ_ASSERT(aPromise);
LOG(("RenameEntry"));
@ -641,9 +651,9 @@ void FileSystemRequestHandler::RenameEntry(
}
aManager->BeginRequest(
[request = FileSystemRenameEntryRequest(aEntry, aName),
onResolve =
SelectResolveCallback<FileSystemMoveEntryResponse, void>(aPromise),
[request = FileSystemRenameEntryRequest(*aEntry, aName),
onResolve = SelectResolveCallback<FileSystemMoveEntryResponse, void>(
aPromise, aEntry, aName),
onReject = GetRejectCallback(aPromise)](const auto& actor) mutable {
actor->SendRenameEntry(request, std::move(onResolve),
std::move(onReject));

Просмотреть файл

@ -70,13 +70,13 @@ class FileSystemRequestHandler {
virtual void MoveEntry(RefPtr<FileSystemManager>& aManager,
FileSystemHandle* aHandle,
const FileSystemEntryMetadata& aEntry,
FileSystemEntryMetadata* const aEntry,
const FileSystemChildMetadata& aNewEntry,
RefPtr<Promise> aPromise, ErrorResult& aError);
virtual void RenameEntry(RefPtr<FileSystemManager>& aManager,
FileSystemHandle* aHandle,
const FileSystemEntryMetadata& aEntry,
FileSystemEntryMetadata* const aEntry,
const Name& aName, RefPtr<Promise> aPromise,
ErrorResult& aError);

Просмотреть файл

@ -420,12 +420,12 @@ IPCResult FileSystemManagerParent::RecvMoveEntry(
aResolver(response);
};
QM_TRY_UNWRAP(bool moved,
mDataManager->MutableDatabaseManagerPtr()->MoveEntry(
aRequest.handle(), aRequest.destHandle()),
IPC_OK(), reportError);
QM_TRY_INSPECT(const EntryId& newId,
mDataManager->MutableDatabaseManagerPtr()->MoveEntry(
aRequest.handle(), aRequest.destHandle()),
IPC_OK(), reportError);
fs::FileSystemMoveEntryResponse response(moved ? NS_OK : NS_ERROR_FAILURE);
fs::FileSystemMoveEntryResponse response(newId);
aResolver(response);
return IPC_OK();
}
@ -445,12 +445,12 @@ IPCResult FileSystemManagerParent::RecvRenameEntry(
aResolver(response);
};
QM_TRY_UNWRAP(bool moved,
mDataManager->MutableDatabaseManagerPtr()->RenameEntry(
aRequest.handle(), aRequest.name()),
IPC_OK(), reportError);
QM_TRY_INSPECT(const EntryId& newId,
mDataManager->MutableDatabaseManagerPtr()->RenameEntry(
aRequest.handle(), aRequest.name()),
IPC_OK(), reportError);
fs::FileSystemMoveEntryResponse response(moved ? NS_OK : NS_ERROR_FAILURE);
fs::FileSystemMoveEntryResponse response(newId);
aResolver(response);
return IPC_OK();
}

Просмотреть файл

@ -131,10 +131,9 @@ class FileSystemDatabaseManager {
*
* @param aHandle Source directory or file
* @param aNewName New entry name
* @return Result<bool, QMResult> False if entry didn't exist, otherwise true
* or error
* @return Result<EntryId, QMResult> The relevant entry id or error
*/
virtual Result<bool, QMResult> RenameEntry(
virtual Result<EntryId, QMResult> RenameEntry(
const FileSystemEntryMetadata& aHandle, const Name& aNewName) = 0;
/**
@ -142,10 +141,9 @@ class FileSystemDatabaseManager {
*
* @param aHandle Source directory or file
* @param aNewDesignation Destination directory and entry name
* @return Result<bool, QMResult> False if entry didn't exist, otherwise true
* or error
* @return Result<EntryId, QMResult> The relevant entry id or error
*/
virtual Result<bool, QMResult> MoveEntry(
virtual Result<EntryId, QMResult> MoveEntry(
const FileSystemEntryMetadata& aHandle,
const FileSystemChildMetadata& aNewDesignation) = 0;

Просмотреть файл

@ -1403,7 +1403,7 @@ nsresult FileSystemDatabaseManagerVersion001::PrepareRenameEntry(
return NS_OK;
}
Result<bool, QMResult> FileSystemDatabaseManagerVersion001::RenameEntry(
Result<EntryId, QMResult> FileSystemDatabaseManagerVersion001::RenameEntry(
const FileSystemEntryMetadata& aHandle, const Name& aNewName) {
const auto& entryId = aHandle.entryId();
@ -1418,7 +1418,7 @@ Result<bool, QMResult> FileSystemDatabaseManagerVersion001::RenameEntry(
// Are we actually renaming?
if (aHandle.entryName() == aNewName) {
return true;
return entryId;
}
QM_TRY(QM_TO_RESULT(PrepareRenameEntry(mConnection, mDataManager, aHandle,
@ -1438,10 +1438,10 @@ Result<bool, QMResult> FileSystemDatabaseManagerVersion001::RenameEntry(
QM_TRY(QM_TO_RESULT(transaction.Commit()));
return true;
return entryId;
}
Result<bool, QMResult> FileSystemDatabaseManagerVersion001::MoveEntry(
Result<EntryId, QMResult> FileSystemDatabaseManagerVersion001::MoveEntry(
const FileSystemEntryMetadata& aHandle,
const FileSystemChildMetadata& aNewDesignation) {
const auto& entryId = aHandle.entryId();
@ -1460,7 +1460,7 @@ Result<bool, QMResult> FileSystemDatabaseManagerVersion001::MoveEntry(
QM_WARNONLY_TRY_UNWRAP(Maybe<bool> maybeSame,
IsSame(mConnection, aHandle, aNewDesignation, isFile));
if (maybeSame && maybeSame.value()) {
return true;
return entryId;
}
QM_TRY(QM_TO_RESULT(PrepareMoveEntry(mConnection, mDataManager, aHandle,
@ -1492,7 +1492,7 @@ Result<bool, QMResult> FileSystemDatabaseManagerVersion001::MoveEntry(
if (aHandle.entryName() == newName) {
QM_TRY(QM_TO_RESULT(transaction.Commit()));
return true;
return entryId;
}
if (isFile) {
@ -1505,7 +1505,7 @@ Result<bool, QMResult> FileSystemDatabaseManagerVersion001::MoveEntry(
QM_TRY(QM_TO_RESULT(transaction.Commit()));
return true;
return entryId;
}
Result<Path, QMResult> FileSystemDatabaseManagerVersion001::Resolve(

Просмотреть файл

@ -71,10 +71,10 @@ class FileSystemDatabaseManagerVersion001 : public FileSystemDatabaseManager {
virtual Result<FileSystemDirectoryListing, QMResult> GetDirectoryEntries(
const EntryId& aParent, PageNumber aPage) const override;
virtual Result<bool, QMResult> RenameEntry(
virtual Result<EntryId, QMResult> RenameEntry(
const FileSystemEntryMetadata& aHandle, const Name& aNewName) override;
virtual Result<bool, QMResult> MoveEntry(
virtual Result<EntryId, QMResult> MoveEntry(
const FileSystemEntryMetadata& aHandle,
const FileSystemChildMetadata& aNewDesignation) override;

Просмотреть файл

@ -242,7 +242,7 @@ struct FileSystemRenameEntryRequest
union FileSystemMoveEntryResponse
{
nsresult;
void_t;
EntryId;
};
} // namespace fs

Просмотреть файл

@ -89,14 +89,14 @@ class MockFileSystemRequestHandler : public FileSystemRequestHandler {
MOCK_METHOD(void, MoveEntry,
(RefPtr<FileSystemManager> & aManager, FileSystemHandle* aHandle,
const FileSystemEntryMetadata& aEntry,
FileSystemEntryMetadata* const aEntry,
const FileSystemChildMetadata& aNewEntry,
RefPtr<Promise> aPromise, ErrorResult& aError),
(override));
MOCK_METHOD(void, RenameEntry,
(RefPtr<FileSystemManager> & aManager, FileSystemHandle* aHandle,
const FileSystemEntryMetadata& aEntry, const Name& aName,
FileSystemEntryMetadata* const aEntry, const Name& aName,
RefPtr<Promise> aPromise, ErrorResult& aError),
(override));

Просмотреть файл

@ -403,8 +403,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
FileSystemEntryMetadata src{firstChildDir, firstChildMeta.childName(),
/* is directory */ true};
FileSystemChildMetadata dest{rootId, src.entryName()};
TEST_TRY_UNWRAP(bool moved, dm->MoveEntry(src, dest));
ASSERT_TRUE(moved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -454,8 +454,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
firstChildDescendantMeta.childName(),
/* is directory */ true};
FileSystemChildMetadata dest{firstChildDir, src.entryName()};
TEST_TRY_UNWRAP(bool moved, dm->MoveEntry(src, dest));
ASSERT_TRUE(moved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -523,8 +523,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
FileSystemEntryMetadata src{testFile, testFileMeta.childName(),
/* is directory */ false};
FileSystemChildMetadata dest{firstChildDir, src.entryName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -543,8 +543,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
FileSystemEntryMetadata src{testFile, testFileMeta.childName(),
/* is directory */ false};
const FileSystemChildMetadata& dest = firstChildDescendantMeta;
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -553,8 +553,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
firstChildDescendantMeta.childName(),
/* is directory */ false};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, testFileMeta));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, testFileMeta));
ASSERT_FALSE(moved.IsEmpty());
TEST_TRY_UNWRAP(EntryId firstChildDescendantCheck,
dm->GetOrCreateDirectory(firstChildDescendantMeta,
@ -568,8 +568,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
firstChildDescendantMeta.childName(),
/* is directory */ true};
const FileSystemChildMetadata& dest = testFileMeta;
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -581,8 +581,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
FileSystemChildMetadata dest{firstChildDir,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
TEST_TRY_UNWRAP(
EntryId testFileCheck,
@ -595,8 +595,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
FileSystemEntryMetadata src{testFile, testFileMeta.childName(),
/* is directory */ false};
FileSystemChildMetadata dest{rootId, src.entryName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -639,8 +639,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
/* is directory */ false};
FileSystemChildMetadata dest{firstChildDir,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -650,8 +650,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
firstChildDescendantMeta.childName(),
/* is directory */ false};
FileSystemChildMetadata dest{rootId, testFileMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
FileSystemChildMetadata oldLocation{firstChildDir,
firstChildDescendantMeta.childName()};
@ -675,8 +675,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
/* is directory */ false};
FileSystemChildMetadata dest{rootId,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -686,8 +686,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
/* is directory */ false};
FileSystemChildMetadata dest{firstChildDir,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -697,8 +697,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
/* is directory */ false};
FileSystemChildMetadata dest{rootId,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
FileSystemChildMetadata oldLocation{firstChildDir,
firstChildDescendantMeta.childName()};
@ -721,8 +721,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
/* is directory */ true};
FileSystemChildMetadata dest{rootId,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -732,8 +732,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
/* is directory */ true};
FileSystemChildMetadata dest{firstChildDir,
firstChildDescendantMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
FileSystemChildMetadata oldLocation{rootId,
firstChildDescendantMeta.childName()};
@ -771,8 +771,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
firstChildDescendantMeta.childName(),
/* is directory */ true};
FileSystemChildMetadata dest{rootId, testFileMeta.childName()};
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -811,8 +811,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
firstChildDescendantMeta.childName()};
// Flag is ignored
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
{
@ -823,8 +823,8 @@ TEST_F(TestFileSystemDatabaseManagerVersion001,
FileSystemChildMetadata dest{firstChildDir, testFileMeta.childName()};
// Flag is ignored
TEST_TRY_UNWRAP(bool isMoved, dm->MoveEntry(src, dest));
ASSERT_TRUE(isMoved);
TEST_TRY_UNWRAP(EntryId moved, dm->MoveEntry(src, dest));
ASSERT_FALSE(moved.IsEmpty());
}
// Check that listings are as expected