/* ** This function deletes a directory and everything under it. ** Deleting directories with "non-file" files, such as links, ** will produce behavior of XP_RemoveFile, since that's what is ** ultimately called. ** ** Return values: zero on failure, non-zero for success. */ int XP_RemoveDirectoryRecursive(const char *name, XP_FileType type) { XP_DirEntryStruct *entry; XP_StatStruct statbuf; int status; char* child; char* dot = "."; char* dotdot = ".."; int ret = 1; XP_Dir dir = XP_OpenDir(name, type); if (!dir) return 0; /* ** Go through the directory entries and delete appropriately */ while ((entry = XP_ReadDir(dir))) { /* ** Allocate space for current name + path separator + directory name + NULL */ child = XP_ALLOC( strlen(name) + 2 + strlen(entry->d_name) ); XP_STRCAT(child,"/"); XP_STRCAT(child,entry->d_name); if (!(status = XP_Stat(child, &statbuf, type))) { if (entry->d_name == dot || entry->d_name == dotdot) { /* Do nothing, rmdir will clean these up */ } else if (S_ISDIR(statbuf.st_mode)) { /* Recursive call to clean out subdirectory */ if (!XP_RemoveDirectoryRecursive(child, type)) ret = 0; } else { /* Everything that's not a directory is a file! */ if (XP_FileRemove(child, type) != 0) ret = 0; } } XP_FREE(child); } /* OK, remove the top-level directory if we can */ if (XP_RemoveDirectory(name, type) != 0) ret = 0; XP_CloseDir(dir); return ret; }
/* Private Native Methods */ void nsInstallFile::NativeAbort() { char* currentName; int result; /* Get the names */ if (tempFile == NULL) return; currentName = tempFile->ToNewCString(); result = XP_FileRemove(currentName, xpURL); XP_ASSERT(result == 0); /* XXX: need to fe_deletefilelater() or something */ delete currentName; }
/* when the back end manages the server list, deleting a server just decrements its ref count, in the old world, we actually delete the server */ static void DIR_DeleteServer(DIR_Server *server) { if (server) { /* when destroying the server check its clear flag to see if things need cleared */ #ifdef XP_FileRemove if (DIR_TestFlag(server, DIR_CLEAR_SERVER)) { if (server->fileName) XP_FileRemove (server->fileName, xpAddrBookNew); } #endif /* XP_FileRemove */ PR_Free(server->prefName); PR_Free(server->description); PR_Free(server->fileName); PR_Free(server->uri); PR_Free(server); } }