Skip to content

Commit

Permalink
Bug 1423917 - P10 - Remove .tmp file in idb drectories in the 2_1to2_…
Browse files Browse the repository at this point in the history
…2 upgrade; r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D21733
  • Loading branch information
chihweitung committed Mar 20, 2019
1 parent 0b9c030 commit db8025b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
49 changes: 49 additions & 0 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7838,6 +7838,8 @@ class QuotaClient final : public mozilla::dom::quota::Client {

nsresult UpgradeStorageFrom1_0To2_0(nsIFile* aDirectory) override;

nsresult UpgradeStorageFrom2_1To2_2(nsIFile* aDirectory) override;

nsresult InitOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup, const nsACString& aOrigin,
const AtomicBool& aCanceled,
Expand Down Expand Up @@ -15916,6 +15918,53 @@ nsresult QuotaClient::UpgradeStorageFrom1_0To2_0(nsIFile* aDirectory) {
return NS_OK;
}

nsresult QuotaClient::UpgradeStorageFrom2_1To2_2(nsIFile* aDirectory) {
AssertIsOnIOThread();
MOZ_ASSERT(aDirectory);

nsCOMPtr<nsIDirectoryEnumerator> entries;
nsresult rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

nsCOMPtr<nsIFile> file;
while (NS_SUCCEEDED((rv = entries->GetNextFile(getter_AddRefs(file)))) &&
file) {
nsString leafName;
rv = file->GetLeafName(leafName);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

bool isDirectory;
rv = file->IsDirectory(&isDirectory);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

if (isDirectory) {
continue;
}

// It's reported that files ending with ".tmp" somehow live in the indexedDB
// directories in Bug 1503883. Such files shouldn't exist in the indexedDB
// directory so remove them in this upgrade.
if (StringEndsWith(leafName, NS_LITERAL_STRING(".tmp"))) {
rv = file->Remove(false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}

if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

return NS_OK;
}

nsresult QuotaClient::InitOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin,
Expand Down
12 changes: 9 additions & 3 deletions dom/quota/test/unit/test_obsoleteOrigins.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ async function testSteps()
// Deprecated client
"storage/default/https+++example.com/asmjs/"
];
const invalidOriginPath = "storage/default/invalid+++example.com/"
const obsoleteFilePath =
"storage/default/https+++example.com/idb/UUID123.tmp";
const invalidOriginPath = "storage/default/invalid+++example.com/";

info("Verifying the obsolete origins are removed after the 2_1To2_2 upgrade" +
" and invalid origins wouldn't block upgrades");
Expand All @@ -29,17 +31,21 @@ async function testSteps()
// directories.
for (let originPath of obsoleteOriginPaths.concat(invalidOriginPath)) {
let originDir = getRelativeFile(originPath);
originDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
originDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt(0o755));
}


let strangeFile = getRelativeFile(obsoleteFilePath);
strangeFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt(0o644));

info("Upgrading");

let request = init();
await requestFinished(request);

info("Verifying the obsolete origins are removed after the 2_1To2_2 upgrade");

for (let originPath of obsoleteOriginPaths) {
for (let originPath of obsoleteOriginPaths.concat(obsoleteFilePath)) {
let folder = getRelativeFile(originPath);
let exists = folder.exists();
ok(!exists, "Obsolete origin was removed during origin initialization");
Expand Down

0 comments on commit db8025b

Please sign in to comment.