mirror of
https://github.com/KjellKod/g3log.git
synced 2025-02-24 23:34:48 +01:00
Correction. SanityFix for illegally written path
thanks to 'Tim L' at CodeProject/g2log
This commit is contained in:
parent
1011af308a
commit
84d625c8cc
@ -72,6 +72,27 @@ std::string prefixSanityFix(std::string prefix)
|
||||
}
|
||||
|
||||
|
||||
std::string pathSanityFix(std::string path, std::string file_name) {
|
||||
// Unify the delimeters,. maybe sketchy solution but it seems to work
|
||||
// on at least win7 + ubuntu. All bets are off for older windows
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
|
||||
// clean up in case of multiples
|
||||
auto contains_end = [&](std::string& in) -> bool {
|
||||
size_t size = in.size();
|
||||
if(!size) return false;
|
||||
char end = in[size-1];
|
||||
return (end == '/' || end == ' ');
|
||||
};
|
||||
|
||||
while(contains_end(path))
|
||||
path.erase(path.size()-1);
|
||||
path.insert(path.end(), '/'); // works on both unix and windows (win7, ubuntu)
|
||||
path.insert(path.size(), file_name);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
std::string createLogFileName(const std::string& verified_prefix)
|
||||
{
|
||||
std::stringstream oss_name;
|
||||
@ -166,7 +187,7 @@ g2LogWorkerImpl::g2LogWorkerImpl(const std::string& log_prefix, const std::strin
|
||||
}
|
||||
|
||||
std::string file_name = createLogFileName(log_prefix_backup_);
|
||||
log_file_with_path_ = log_directory + file_name;
|
||||
log_file_with_path_ = pathSanityFix(log_file_with_path_, file_name);
|
||||
outptr_ = createLogFile(log_file_with_path_);
|
||||
assert((nullptr != outptr_) && "cannot open log file at startup");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user