示例#1
0
already_AddRefed<Promise>
Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
                          ErrorResult& aRv)
{
  nsresult error = NS_OK;
  nsAutoString realPath;
  nsRefPtr<BlobImpl> blob;

  // Check and get the target path.

  if (aPath.IsFile()) {
    blob = aPath.GetAsFile().Impl();
  } else if (aPath.IsString()) {
    if (!DOMPathToRealPath(aPath.GetAsString(), realPath)) {
      error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
    }
  } else if (!mFileSystem->IsSafeDirectory(&aPath.GetAsDirectory())) {
    error = NS_ERROR_DOM_SECURITY_ERR;
  } else {
    realPath = aPath.GetAsDirectory().mPath;
    // The target must be a descendant of this directory.
    if (!FileSystemUtils::IsDescendantPath(mPath, realPath)) {
      error = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR;
    }
  }

  nsRefPtr<RemoveTask> task = new RemoveTask(mFileSystem, mPath, blob, realPath,
    aRecursive, aRv);
  if (aRv.Failed()) {
    return nullptr;
  }
  task->SetError(error);
  FileSystemPermissionRequest::RequestForTask(task);
  return task->GetPromise();
}
示例#2
0
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();
}
示例#3
0
already_AddRefed<Promise>
Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive)
{
  nsresult error = NS_OK;
  nsString realPath;
  nsCOMPtr<nsIDOMFile> file;

  // Check and get the target path.

  if (aPath.IsFile()) {
    file = aPath.GetAsFile();
    goto parameters_check_done;
  }

  if (aPath.IsString()) {
    if (!DOMPathToRealPath(aPath.GetAsString(), realPath)) {
      error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
    }
    goto parameters_check_done;
  }

  if (!mFileSystem->IsSafeDirectory(&aPath.GetAsDirectory())) {
    error = NS_ERROR_DOM_SECURITY_ERR;
    goto parameters_check_done;
  }

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

parameters_check_done:

  nsRefPtr<RemoveTask> task = new RemoveTask(mFileSystem, mPath, file, realPath,
    aRecursive);
  task->SetError(error);
  FileSystemPermissionRequest::RequestForTask(task);
  return task->GetPromise();
}