2011-12-15 23:34:24 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
#include "FileManager.h"
|
|
|
|
|
|
|
|
#include "mozIStorageConnection.h"
|
|
|
|
#include "mozIStorageStatement.h"
|
2012-12-17 11:25:10 -08:00
|
|
|
#include "nsIInputStream.h"
|
2011-12-15 23:34:24 -08:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2012-02-20 10:35:45 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "mozilla/dom/quota/Utilities.h"
|
2011-12-15 23:34:24 -08:00
|
|
|
#include "mozStorageCID.h"
|
2012-02-20 10:35:45 -08:00
|
|
|
#include "mozStorageHelper.h"
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "Client.h"
|
2011-12-15 23:34:24 -08:00
|
|
|
#include "FileInfo.h"
|
|
|
|
#include "IndexedDatabaseManager.h"
|
2012-08-24 11:51:33 -07:00
|
|
|
#include "OpenDatabaseHelper.h"
|
|
|
|
|
2012-12-17 11:25:10 -08:00
|
|
|
#include "IndexedDatabaseInlines.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2012-12-17 11:25:10 -08:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
USING_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
PLDHashOperator
|
2012-08-22 08:56:38 -07:00
|
|
|
EnumerateToTArray(const uint64_t& aKey,
|
2011-12-15 23:34:24 -08:00
|
|
|
FileInfo* aValue,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aValue, "Null pointer!");
|
|
|
|
NS_ASSERTION(aUserArg, "Null pointer!");
|
|
|
|
|
|
|
|
nsTArray<FileInfo*>* array =
|
|
|
|
static_cast<nsTArray<FileInfo*>*>(aUserArg);
|
|
|
|
|
|
|
|
array->AppendElement(aValue);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
already_AddRefed<nsIFile>
|
|
|
|
GetDirectoryFor(const nsAString& aDirectoryPath)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> directory =
|
|
|
|
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(directory, nullptr);
|
|
|
|
|
|
|
|
nsresult rv = directory->InitWithPath(aDirectoryPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
|
|
|
return directory.forget();
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
nsresult
|
2011-12-20 03:23:27 -08:00
|
|
|
FileManager::Init(nsIFile* aDirectory,
|
2012-08-24 11:51:33 -07:00
|
|
|
mozIStorageConnection* aConnection)
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
2012-08-24 11:51:33 -07:00
|
|
|
NS_ASSERTION(aDirectory, "Null directory!");
|
|
|
|
NS_ASSERTION(aConnection, "Null connection!");
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
mFileInfos.Init();
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
bool exists;
|
|
|
|
nsresult rv = aDirectory->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
bool isDirectory;
|
|
|
|
rv = aDirectory->IsDirectory(&isDirectory);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(isDirectory, NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
rv = aDirectory->GetPath(mDirectoryPath);
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
nsCOMPtr<nsIFile> journalDirectory;
|
|
|
|
rv = aDirectory->Clone(getter_AddRefs(journalDirectory));
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
rv = journalDirectory->Append(NS_LITERAL_STRING(JOURNAL_DIRECTORY_NAME));
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
rv = journalDirectory->Exists(&exists);
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
if (exists) {
|
|
|
|
bool isDirectory;
|
|
|
|
rv = journalDirectory->IsDirectory(&isDirectory);
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-08-24 11:51:33 -07:00
|
|
|
NS_ENSURE_TRUE(isDirectory, NS_ERROR_FAILURE);
|
2011-12-15 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
rv = journalDirectory->GetPath(mJournalDirectoryPath);
|
2011-12-15 23:34:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
2012-08-24 11:51:33 -07:00
|
|
|
rv = aConnection->CreateStatement(NS_LITERAL_CSTRING(
|
2011-12-15 23:34:24 -08:00
|
|
|
"SELECT id, refcount "
|
|
|
|
"FROM file"
|
|
|
|
), getter_AddRefs(stmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool hasResult;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t id;
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = stmt->GetInt64(0, &id);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t refcount;
|
2011-12-15 23:34:24 -08:00
|
|
|
rv = stmt->GetInt32(1, &refcount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ASSERTION(refcount, "This shouldn't happen!");
|
|
|
|
|
|
|
|
nsRefPtr<FileInfo> fileInfo = FileInfo::Create(this, id);
|
|
|
|
fileInfo->mDBRefCnt = refcount;
|
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
mFileInfos.Put(id, fileInfo);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
mLastFileId = std::max(id, mLastFileId);
|
2011-12-15 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
FileManager::Invalidate()
|
|
|
|
{
|
|
|
|
if (IndexedDatabaseManager::IsClosed()) {
|
|
|
|
NS_ERROR("Shouldn't be called after shutdown!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<FileInfo*> fileInfos;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
|
|
|
|
|
|
|
NS_ASSERTION(!mInvalidated, "Invalidate more than once?!");
|
|
|
|
mInvalidated = true;
|
|
|
|
|
|
|
|
fileInfos.SetCapacity(mFileInfos.Count());
|
|
|
|
mFileInfos.EnumerateRead(EnumerateToTArray, &fileInfos);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < fileInfos.Length(); i++) {
|
2011-12-15 23:34:24 -08:00
|
|
|
FileInfo* fileInfo = fileInfos.ElementAt(i);
|
|
|
|
fileInfo->ClearDBRefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIFile>
|
|
|
|
FileManager::GetDirectory()
|
|
|
|
{
|
2012-08-24 11:51:33 -07:00
|
|
|
return GetDirectoryFor(mDirectoryPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIFile>
|
|
|
|
FileManager::GetJournalDirectory()
|
|
|
|
{
|
|
|
|
return GetDirectoryFor(mJournalDirectoryPath);
|
|
|
|
}
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
already_AddRefed<nsIFile>
|
|
|
|
FileManager::EnsureJournalDirectory()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> journalDirectory = GetDirectoryFor(mJournalDirectoryPath);
|
|
|
|
NS_ENSURE_TRUE(journalDirectory, nullptr);
|
|
|
|
|
|
|
|
bool exists;
|
|
|
|
nsresult rv = journalDirectory->Exists(&exists);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
if (exists) {
|
|
|
|
bool isDirectory;
|
|
|
|
rv = journalDirectory->IsDirectory(&isDirectory);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
NS_ENSURE_TRUE(isDirectory, nullptr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = journalDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return journalDirectory.forget();
|
2011-12-15 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<FileInfo>
|
2012-08-22 08:56:38 -07:00
|
|
|
FileManager::GetFileInfo(int64_t aId)
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
if (IndexedDatabaseManager::IsClosed()) {
|
|
|
|
NS_ERROR("Shouldn't be called after shutdown!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-12-15 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
FileInfo* fileInfo = nullptr;
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
|
|
|
fileInfo = mFileInfos.Get(aId);
|
|
|
|
}
|
|
|
|
nsRefPtr<FileInfo> result = fileInfo;
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<FileInfo>
|
|
|
|
FileManager::GetNewFileInfo()
|
|
|
|
{
|
|
|
|
if (IndexedDatabaseManager::IsClosed()) {
|
|
|
|
NS_ERROR("Shouldn't be called after shutdown!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-12-15 23:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<FileInfo> fileInfo;
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t id = mLastFileId + 1;
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
fileInfo = FileInfo::Create(this, id);
|
|
|
|
|
2012-05-18 10:30:49 -07:00
|
|
|
mFileInfos.Put(id, fileInfo);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
mLastFileId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<FileInfo> result = fileInfo.forget();
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
// static
|
2011-12-15 23:34:24 -08:00
|
|
|
already_AddRefed<nsIFile>
|
2012-08-22 08:56:38 -07:00
|
|
|
FileManager::GetFileForId(nsIFile* aDirectory, int64_t aId)
|
2011-12-15 23:34:24 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aDirectory, "Null pointer!");
|
|
|
|
|
|
|
|
nsAutoString id;
|
|
|
|
id.AppendInt(aId);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = aDirectory->Clone(getter_AddRefs(file));
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
rv = file->Append(id);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2011-12-15 23:34:24 -08:00
|
|
|
|
|
|
|
return file.forget();
|
|
|
|
}
|
2012-08-24 11:51:33 -07:00
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
2012-12-17 11:25:10 -08:00
|
|
|
FileManager::InitDirectory(nsIFile* aDirectory,
|
2012-08-24 11:51:33 -07:00
|
|
|
nsIFile* aDatabaseFile,
|
2012-12-17 11:25:10 -08:00
|
|
|
const nsACString& aOrigin)
|
2012-08-24 11:51:33 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aDirectory, "Null directory!");
|
|
|
|
NS_ASSERTION(aDatabaseFile, "Null database file!");
|
|
|
|
|
|
|
|
bool exists;
|
|
|
|
nsresult rv = aDirectory->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDirectory;
|
|
|
|
rv = aDirectory->IsDirectory(&isDirectory);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(isDirectory, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> journalDirectory;
|
|
|
|
rv = aDirectory->Clone(getter_AddRefs(journalDirectory));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = journalDirectory->Append(NS_LITERAL_STRING(JOURNAL_DIRECTORY_NAME));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = journalDirectory->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
rv = journalDirectory->IsDirectory(&isDirectory);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(isDirectory, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
rv = journalDirectory->GetDirectoryEntries(getter_AddRefs(entries));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool hasElements;
|
|
|
|
rv = entries->HasMoreElements(&hasElements);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (hasElements) {
|
|
|
|
nsCOMPtr<mozIStorageConnection> connection;
|
2012-12-17 11:25:10 -08:00
|
|
|
rv = OpenDatabaseHelper::CreateDatabaseConnection(aDatabaseFile,
|
|
|
|
aDirectory, NullString(), aOrigin, getter_AddRefs(connection));
|
2012-08-24 11:51:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mozStorageTransaction transaction(connection, false);
|
|
|
|
|
|
|
|
rv = connection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"CREATE VIRTUAL TABLE fs USING filesystem;"
|
|
|
|
));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
rv = connection->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT name, (name IN (SELECT id FROM file)) FROM fs "
|
|
|
|
"WHERE path = :path"
|
|
|
|
), getter_AddRefs(stmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsString path;
|
|
|
|
rv = journalDirectory->GetPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("path"), path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool hasResult;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
|
|
|
|
nsString name;
|
|
|
|
rv = stmt->GetString(0, name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
int32_t flag = stmt->AsInt32(1);
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = aDirectory->Clone(getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = file->Append(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(file->Remove(false))) {
|
|
|
|
NS_WARNING("Failed to remove orphaned file!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> journalFile;
|
|
|
|
rv = journalDirectory->Clone(getter_AddRefs(journalFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = journalFile->Append(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(journalFile->Remove(false))) {
|
|
|
|
NS_WARNING("Failed to remove journal file!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = connection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE fs;"
|
|
|
|
));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
transaction.Commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-17 11:25:10 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
FileManager::GetUsage(nsIFile* aDirectory, uint64_t* aUsage)
|
|
|
|
{
|
|
|
|
uint64_t usage = 0;
|
2012-08-24 11:51:33 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
2012-12-17 11:25:10 -08:00
|
|
|
nsresult rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
|
2012-08-24 11:51:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool hasMore;
|
|
|
|
while (NS_SUCCEEDED((rv = entries->HasMoreElements(&hasMore))) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
rv = entries->GetNext(getter_AddRefs(entry));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(entry);
|
|
|
|
NS_ENSURE_TRUE(file, NS_NOINTERFACE);
|
|
|
|
|
|
|
|
nsString leafName;
|
|
|
|
rv = file->GetLeafName(leafName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (leafName.EqualsLiteral(JOURNAL_DIRECTORY_NAME)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-12-17 11:25:10 -08:00
|
|
|
int64_t fileSize;
|
|
|
|
rv = file->GetFileSize(&fileSize);
|
2012-08-24 11:51:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-12-17 11:25:10 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
quota::IncrementUsage(&usage, uint64_t(fileSize));
|
2012-08-24 11:51:33 -07:00
|
|
|
}
|
|
|
|
|
2012-12-17 11:25:10 -08:00
|
|
|
*aUsage = usage;
|
2012-08-24 11:51:33 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|