Пример #1
0
/**
 * \fn void ModuleHandler::SanitizeRuntime()
 * \brief Deletes all files in the runtime directory.
 */
void ModuleHandler::SanitizeRuntime()
{
	Log(LOG_DEBUG) << "Cleaning up runtime directory.";
	Flux::string dirbuf = binary_dir + "/runtime/";

	if(!TextFile::IsDirectory(dirbuf))
	{
#ifndef _WIN32

		if(mkdir(dirbuf.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
			throw CoreException(printfify("Error making new runtime directory: %s", strerror(errno)));

#else

		if(!CreateDirectory(dirbuf.c_str(), NULL))
			throw CoreException(printfify("Error making runtime new directory: %s", strerror(errno)));

#endif
	}
	else
	{
		Flux::vector files = TextFile::DirectoryListing(dirbuf);

		for(Flux::vector::iterator it = files.begin(); it != files.end(); ++it)
			Delete(Flux::string(dirbuf + (*it)).c_str());
	}
}
Пример #2
0
/**
 * \fn void CheckLogDelete(Log *log)
 * \brief Check to see if logs need to be removed due to old age
 * \param log A log class variable
 */
void CheckLogDelete(Log *log)
{
	Flux::string dir = binary_dir + "/logs/";

	if(!TextFile::IsDirectory(dir))
	{
		Log(LOG_TERMINAL) << "Directory " << dir << " does not exist, making new directory.";
#ifndef _WIN32

		if(mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
			throw LogException("Failed to create directory " + dir + ": " + Flux::string(strerror(errno)));

#else

		if(!CreateDirectory(dir.c_str(), NULL))
			throw LogException("Failed to create directory " + dir + ": " + Flux::string(strerror(errno)));

#endif

	}

	Flux::vector files = TextFile::DirectoryListing(dir);

	if(log)
		files.push_back(log->filename);

	if(files.empty())
		Log(LOG_TERMINAL) << "No Logs!";

	for(Flux::vector::iterator it = files.begin(); it != files.end(); ++it)
	{
		Flux::string file = dir + (*it);

		if(TextFile::IsFile(file))
		{
			Flux::string t = file.isolate('-', ' ').strip('-');
			int timestamp = static_cast<int>(t);

			if(timestamp > (time(NULL) - 86400 * Config->LogAge) && timestamp != starttime)
			{
				Delete(file.c_str());
				Log(LOG_DEBUG) << "Deleted old logfile " << file;
			}
		}
	}
}
Пример #3
0
/**Rehash void
 * \fn void ReadConfig()
 * \deprecated This will be removed soon.
 * This will re-read the config file values when told to do so
 */
void ModuleHandler::LoadModuleList(const Flux::vector &list)
{
	for(Flux::vector::const_iterator it = list.begin(); it != list.end(); ++it)
	{
		ModErr e = LoadModule(*it);

		if(e != MOD_ERR_OK)
			Log() << "Error loading Module " << *it << ": " << DecodeModErr(e);
	}

//   sepstream sep(Config->Modules, ',');
//   Flux::string tok;
//
//   while(sep.GetToken(tok))
//   {
//     tok.trim();
//     ModErr e = ModuleHandler::LoadModule(tok);
//     if(e != MOD_ERR_OK)
//       Log() << "ERROR loading Module " << tok << ": " << DecodeModErr(e);
//   }
}