Esempio n. 1
0
bool DeleteListRecursively( FS* fs, FSPath path, FSList& list )
{
	const int cnt = path.Count();
	int ret_err;

	for ( FSNode* node = list.First(); node; node = node->next )
	{
		if ( node->extType )
		{
			continue;
		}

		path.SetItemStr( cnt, node->Name() );

		if ( node->IsDir() && !node->st.IsLnk() )
		{
			if ( !DeleteDirRecursively( fs, path ) )
			{
				return false;
			}
		}
		else if ( fs->Delete( path, &ret_err, nullptr ) != 0 )
		{
			return false;
		}
	}

	return true;
}
Esempio n. 2
0
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
    INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
#ifdef _WIN32
    // Find the first file in the directory.
    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile((directory + "\\*").c_str(), &ffd);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return false;
    }

    // windows loop
    do
    {
        const std::string virtualName = ffd.cFileName;
#else
    struct dirent dirent, *result = NULL;
    DIR *dirp = opendir(directory.c_str());
    if (!dirp)
        return false;

    // non windows loop
    while (!readdir_r(dirp, &dirent, &result) && result)
    {
        const std::string virtualName = result->d_name;
#endif

        // check for "." and ".."
        if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
                ((virtualName[0] == '.') && (virtualName[1] == '.') &&
                 (virtualName[2] == '\0')))
            continue;

        std::string newPath = directory + DIR_SEP + virtualName;
        if (IsDirectory(newPath))
        {
            if (!DeleteDirRecursively(newPath))
                return false;
        }
        else
        {
            if (!File::Delete(newPath))
                return false;
        }

#ifdef _WIN32
    }
    while (FindNextFile(hFind, &ffd) != 0);
    FindClose(hFind);
#else
    }
    closedir(dirp);
#endif
    File::DeleteDir(directory);

    return true;
}
Esempio n. 3
0
void RemoveAllWcmTempDirs()
{
	for ( auto &iter : g_TempDirUriList )
	{
		std::vector<unicode_t> TempUri = iter.second;

		if ( TempUri.data() )
		{
			FSPath path;
			clPtr<FS> fs = ParzeURI( TempUri.data(), path, std::vector<clPtr<FS>>() );

			DeleteDirRecursively( fs.Ptr(), path );
		}
	}
}
Esempio n. 4
0
void RemoveWcmTempDir( const int Id )
{
	auto iter = g_TempDirUriList.find( Id );

	if ( iter != g_TempDirUriList.end() )
	{
		std::vector<unicode_t> TempUri = iter->second;

		if ( TempUri.data() )
		{
			FSPath path;
			clPtr<FS> fs = ParzeURI( TempUri.data(), path, std::vector<clPtr<FS>>() );
			
			DeleteDirRecursively( fs.Ptr(), path );
		}
	}
}
Esempio n. 5
0
bool DeleteDirRecursively(const std::string &directory)
{
    const static auto callback = [](unsigned* num_entries_out,
                                    const std::string& directory,
                                    const std::string& virtual_name) -> bool {
        std::string new_path = directory + DIR_SEP_CHR + virtual_name;
        if (IsDirectory(new_path))
            return DeleteDirRecursively(new_path);

        return Delete(new_path);
    };

    if (!ForeachDirectoryEntry(nullptr, directory, callback))
        return false;

    // Delete the outermost directory
    FileUtil::DeleteDir(directory);
    return true;
}
Esempio n. 6
0
bool DeleteDirRecursively(const std::string &directory)
{
    const static auto callback = [](const std::string& directory,
                                    const std::string& virtual_name) -> int {
        std::string new_path = directory + DIR_SEP_CHR + virtual_name;
        if (IsDirectory(new_path)) {
            if (!DeleteDirRecursively(new_path)) {
                return -2;
            }
        } else if (!Delete(new_path)) {
            return -2;
        }
        return 0;
    };

    if (ScanDirectoryTreeAndCallback(directory, callback) == -2) {
        return false;
    }
    FileUtil::DeleteDir(directory);

    return true;
}
Esempio n. 7
0
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
#if PPSSPP_PLATFORM(UWP)
	return false;
#else
	INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());

#ifdef _WIN32

	// Find the first file in the directory.
	WIN32_FIND_DATA ffd;
	HANDLE hFind = FindFirstFile(ConvertUTF8ToWString(directory + "\\*").c_str(), &ffd);

	if (hFind == INVALID_HANDLE_VALUE)
	{
		return false;
	}
		
	// windows loop
	do
	{
		const std::string virtualName = ConvertWStringToUTF8(ffd.cFileName);
#else
	struct dirent *result = NULL;
	DIR *dirp = opendir(directory.c_str());
	if (!dirp)
		return false;

	// non windows loop
	while ((result = readdir(dirp)))
	{
		const std::string virtualName = result->d_name;
#endif
		// check for "." and ".."
		if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
			((virtualName[0] == '.') && (virtualName[1] == '.') && 
			 (virtualName[2] == '\0')))
			continue;

		std::string newPath = directory + DIR_SEP + virtualName;
		if (IsDirectory(newPath))
		{
			if (!DeleteDirRecursively(newPath))
			{
#ifndef _WIN32
				closedir(dirp);
#else
				FindClose(hFind);
#endif
				return false;
			}
		}
		else
		{
			if (!File::Delete(newPath))
			{
#ifndef _WIN32
				closedir(dirp);
#else
				FindClose(hFind);
#endif
				return false;
			}
		}

#ifdef _WIN32
	} while (FindNextFile(hFind, &ffd) != 0);
	FindClose(hFind);
#else
	}
	closedir(dirp);
#endif
	return File::DeleteDir(directory);
#endif
}
Esempio n. 8
0
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
    LOG_TRACE(Common_Filesystem, "%s", directory.c_str());
#ifdef _WIN32
    // Find the first file in the directory.
    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return false;
    }

    // windows loop
    do
    {
        const std::string virtualName(Common::TStrToUTF8(ffd.cFileName));
#else
    struct dirent dirent, *result = nullptr;
    DIR *dirp = opendir(directory.c_str());
    if (!dirp)
        return false;

    // non windows loop
    while (!readdir_r(dirp, &dirent, &result) && result)
    {
        const std::string virtualName = result->d_name;
#endif

        // check for "." and ".."
        if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
            ((virtualName[0] == '.') && (virtualName[1] == '.') &&
             (virtualName[2] == '\0')))
            continue;

        std::string newPath = directory + DIR_SEP_CHR + virtualName;
        if (IsDirectory(newPath))
        {
            if (!DeleteDirRecursively(newPath))
            {
                #ifndef _WIN32
                closedir(dirp);
                #endif

                return false;
            }
        }
        else
        {
            if (!FileUtil::Delete(newPath))
            {
                #ifndef _WIN32
                closedir(dirp);
                #endif

                return false;
            }
        }

#ifdef _WIN32
    } while (FindNextFile(hFind, &ffd) != 0);
    FindClose(hFind);
#else
    }
    closedir(dirp);
#endif
    FileUtil::DeleteDir(directory);

    return true;
}
Esempio n. 9
0
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string& directory)
{
  INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
  bool success = true;

#ifdef _WIN32
  // Find the first file in the directory.
  WIN32_FIND_DATA ffd;
  HANDLE hFind = FindFirstFile(UTF8ToTStr(directory + "\\*").c_str(), &ffd);

  if (hFind == INVALID_HANDLE_VALUE)
  {
    FindClose(hFind);
    return false;
  }

  // Windows loop
  do
  {
    const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
  DIR* dirp = opendir(directory.c_str());
  if (!dirp)
    return false;

  // non Windows loop
  while (dirent* result = readdir(dirp))
  {
    const std::string virtualName = result->d_name;
#endif

    // check for "." and ".."
    if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
        ((virtualName[0] == '.') && (virtualName[1] == '.') && (virtualName[2] == '\0')))
      continue;

    std::string newPath = directory + DIR_SEP_CHR + virtualName;
    if (IsDirectory(newPath))
    {
      if (!DeleteDirRecursively(newPath))
      {
        success = false;
        break;
      }
    }
    else
    {
      if (!File::Delete(newPath))
      {
        success = false;
        break;
      }
    }

#ifdef _WIN32
  } while (FindNextFile(hFind, &ffd) != 0);
  FindClose(hFind);
#else
  }
  closedir(dirp);
#endif
  if (success)
    File::DeleteDir(directory);

  return success;
}