Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsDeleteDir.cpp File Reference
#include "nsDeleteDir.h"
#include "nsIFile.h"
#include "nsString.h"
#include "prthread.h"

Go to the source code of this file.

Functions

 PR_STATIC_CALLBACK (void) DeleteDirThreadFunc(void *arg)
nsresult DeleteDir (nsIFile *dirIn, PRBool moveToTrash, PRBool sync)
nsresult GetTrashDir (nsIFile *target, nsCOMPtr< nsIFile > *result)

Function Documentation

nsresult DeleteDir ( nsIFile dirIn,
PRBool  moveToTrash,
PRBool  sync 
)

Definition at line 51 of file nsDeleteDir.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIFile> trash, dir;

  // Need to make a clone of this since we don't want to modify the input
  // file object.
  rv = dirIn->Clone(getter_AddRefs(dir));
  if (NS_FAILED(rv))
    return rv;

  if (moveToTrash)
  {
    rv = GetTrashDir(dir, &trash);
    if (NS_FAILED(rv))
      return rv;

    nsCOMPtr<nsIFile> subDir;
    rv = trash->Clone(getter_AddRefs(subDir));
    if (NS_FAILED(rv))
      return rv;

    rv = subDir->AppendNative(NS_LITERAL_CSTRING("Trash"));
    if (NS_FAILED(rv))
      return rv;

    rv = subDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700);
    if (NS_FAILED(rv))
      return rv;

    rv = dir->MoveToNative(subDir, EmptyCString());
    if (NS_FAILED(rv))
      return rv;
  }
  else
  {
    // we want to pass a clone of the original off to the worker thread.
    trash.swap(dir);
  }

  // Steal ownership of trash directory; let the thread release it.
  nsIFile *trashRef = nsnull;
  trash.swap(trashRef);

  if (sync)
  {
    DeleteDirThreadFunc(trashRef);
  }
  else
  {
    // now, invoke the worker thread
    PRThread *thread = PR_CreateThread(PR_USER_THREAD,
                                       DeleteDirThreadFunc,
                                       trashRef,
                                       PR_PRIORITY_LOW,
                                       PR_GLOBAL_THREAD,
                                       PR_UNJOINABLE_THREAD,
                                       0);
    if (!thread)
      return NS_ERROR_UNEXPECTED;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult GetTrashDir ( nsIFile target,
nsCOMPtr< nsIFile > *  result 
)

Definition at line 116 of file nsDeleteDir.cpp.

{
  nsresult rv = target->Clone(getter_AddRefs(*result));
  if (NS_FAILED(rv))
    return rv;

  nsCAutoString leaf;
  rv = (*result)->GetNativeLeafName(leaf);
  if (NS_FAILED(rv))
    return rv;
  leaf.AppendLiteral(".Trash");

  return (*result)->SetNativeLeafName(leaf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 44 of file nsDeleteDir.cpp.

{
  nsIFile *dir = NS_STATIC_CAST(nsIFile *, arg);
  dir->Remove(PR_TRUE);
  NS_RELEASE(dir);
}