Skip to content

Commit

Permalink
Bug 1299500 - Get rid of DeviceStorage API - part 7 - Directory::Remo…
Browse files Browse the repository at this point in the history
…ve, r=ehsan
  • Loading branch information
bakulf committed Mar 8, 2017
1 parent 4230518 commit c18b6d5
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 485 deletions.
71 changes: 0 additions & 71 deletions dom/filesystem/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "GetDirectoryListingTask.h"
#include "GetFileOrDirectoryTask.h"
#include "GetFilesTask.h"
#include "RemoveTask.h"
#include "WorkerPrivate.h"

#include "nsCharSeparatedTokenizer.h"
Expand Down Expand Up @@ -205,76 +204,6 @@ Directory::Get(const nsAString& aPath, ErrorResult& aRv)
return task->GetPromise();
}

already_AddRefed<Promise>
Directory::Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv)
{
// Only exposed for DeviceStorage.
MOZ_ASSERT(NS_IsMainThread());
return RemoveInternal(aPath, false, aRv);
}

already_AddRefed<Promise>
Directory::RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv)
{
// Only exposed for DeviceStorage.
MOZ_ASSERT(NS_IsMainThread());
return RemoveInternal(aPath, true, aRv);
}

already_AddRefed<Promise>
Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
ErrorResult& aRv)
{
// Only exposed for DeviceStorage.
MOZ_ASSERT(NS_IsMainThread());

nsresult error = NS_OK;
nsCOMPtr<nsIFile> realPath;

// Check and get the target path.

RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

// If this is a File
if (aPath.IsFile()) {
if (!fs->GetRealPath(aPath.GetAsFile().Impl(),
getter_AddRefs(realPath))) {
error = NS_ERROR_DOM_SECURITY_ERR;
}

// If this is a string
} else if (aPath.IsString()) {
error = DOMPathToRealPath(aPath.GetAsString(), getter_AddRefs(realPath));

// Directory
} else {
MOZ_ASSERT(aPath.IsDirectory());
if (!fs->IsSafeDirectory(&aPath.GetAsDirectory())) {
error = NS_ERROR_DOM_SECURITY_ERR;
} else {
realPath = aPath.GetAsDirectory().mFile;
}
}

// The target must be a descendant of this directory.
if (!FileSystemUtils::IsDescendantPath(mFile, realPath)) {
error = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR;
}

RefPtr<RemoveTaskChild> task =
RemoveTaskChild::Create(fs, mFile, realPath, aRecursive, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

task->SetError(error);
FileSystemPermissionRequest::RequestForTask(task);
return task->GetPromise();
}

void
Directory::GetPath(nsAString& aRetval, ErrorResult& aRv)
{
Expand Down
10 changes: 0 additions & 10 deletions dom/filesystem/Directory.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ class Directory final
already_AddRefed<Promise>
Get(const nsAString& aPath, ErrorResult& aRv);

already_AddRefed<Promise>
Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);

already_AddRefed<Promise>
RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);

// From https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface :

void
Expand Down Expand Up @@ -132,10 +126,6 @@ class Directory final
nsresult
DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;

already_AddRefed<Promise>
RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
ErrorResult& aRv);

nsCOMPtr<nsISupports> mParent;
RefPtr<FileSystemBase> mFileSystem;
nsCOMPtr<nsIFile> mFile;
Expand Down
2 changes: 0 additions & 2 deletions dom/filesystem/FileSystemRequestParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "GetDirectoryListingTask.h"
#include "GetFileOrDirectoryTask.h"
#include "RemoveTask.h"

#include "mozilla/dom/FileSystemBase.h"

Expand Down Expand Up @@ -50,7 +49,6 @@ FileSystemRequestParent::Initialize(const FileSystemParams& aParams)
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetDirectoryListing)
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory)
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFiles)
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(Remove)

default: {
MOZ_CRASH("not reached");
Expand Down
9 changes: 0 additions & 9 deletions dom/filesystem/PFileSystemParams.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,11 @@ struct FileSystemGetFileOrDirectoryParams
nsString realPath;
};

struct FileSystemRemoveParams
{
nsString filesystem;
nsString directory;
nsString targetDirectory;
bool recursive;
};

union FileSystemParams
{
FileSystemGetDirectoryListingParams;
FileSystemGetFilesParams;
FileSystemGetFileOrDirectoryParams;
FileSystemRemoveParams;
};

} // dom namespace
Expand Down
Loading

0 comments on commit c18b6d5

Please sign in to comment.