Improved Input::checkHeaderTimes function to be less spammy about non-file inputs

This commit is contained in:
Thulinma 2016-09-22 09:41:42 +02:00
parent 26f4b2efd9
commit 29c37fd4e9

View file

@ -69,32 +69,20 @@ namespace Mist {
isBuffer = false; isBuffer = false;
} }
void Input::checkHeaderTimes(std::string streamFile){ void Input::checkHeaderTimes(std::string streamFile) {
if (streamFile == "-" || streamFile == "push://") { struct stat bufStream;
struct stat bufHeader;
if (stat(streamFile.c_str(), &bufStream) != 0) {
INSANE_MSG("Source is not a file - ignoring header check");
return; return;
} }
std::string headerFile = streamFile + ".dtsh"; std::string headerFile = streamFile + ".dtsh";
FILE * tmp = fopen(headerFile.c_str(),"r"); if (stat(headerFile.c_str(), &bufHeader) != 0) {
if (tmp == NULL){ INSANE_MSG("No header exists to compare - ignoring header check");
DEBUG_MSG(DLVL_HIGH, "Can't open header: %s. Assuming all is fine.", headerFile.c_str() );
return;
}
struct stat bufStream;
struct stat bufHeader;
//fstat(fileno(streamFile), &bufStream);
//fstat(fileno(tmp), &bufHeader);
if (stat(streamFile.c_str(), &bufStream) !=0 || stat(headerFile.c_str(), &bufHeader) !=0){
DEBUG_MSG(DLVL_HIGH, "Could not compare stream and header timestamps - assuming all is fine.");
fclose(tmp);
return; return;
} }
if (bufHeader.st_mtime < bufStream.st_mtime) {
int timeStream = bufStream.st_mtime; INFO_MSG("Overwriting outdated DTSH header file: %s ", headerFile.c_str());
int timeHeader = bufHeader.st_mtime;
fclose(tmp);
if (timeHeader < timeStream){
//delete filename
INFO_MSG("Overwriting outdated DTSH header file: %s ",headerFile.c_str());
remove(headerFile.c_str()); remove(headerFile.c_str());
} }
} }