// Private function! used by Flux::string.explode() Flux::vector __ParamString(const Flux::string &str, char delim = ' ') { Flux::vector ret; Flux::string token; sepstream tok(str, delim); while (tok.GetToken(token)) ret.push_back(token); return ret; }
/** * \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; } } } }