v1.5.t9
The app is hard crashing now but I was able to determine the cause this time. Must functions in filesystem tend to abort if the filesystem object doesn't exists. Added protection where needed to prevent crashing
This commit is contained in:
parent
954fdfba0b
commit
a5ee164b4e
|
@ -52,15 +52,12 @@ bool createDirTree(const string &full_path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileExists(const string& name)
|
|
||||||
{
|
|
||||||
return access(name.c_str(), F_OK) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<string> lsFilesInDir(const string &path, const string &ext)
|
vector<string> lsFilesInDir(const string &path, const string &ext)
|
||||||
{
|
{
|
||||||
vector<string> names;
|
vector<string> names;
|
||||||
|
|
||||||
|
if (exists(path))
|
||||||
|
{
|
||||||
for (auto &entry : directory_iterator(path))
|
for (auto &entry : directory_iterator(path))
|
||||||
{
|
{
|
||||||
if (entry.is_regular_file())
|
if (entry.is_regular_file())
|
||||||
|
@ -73,6 +70,7 @@ vector<string> lsFilesInDir(const string &path, const string &ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sort(names.begin(), names.end());
|
sort(names.begin(), names.end());
|
||||||
|
|
||||||
|
@ -83,6 +81,8 @@ vector<string> lsDirsInDir(const string &path)
|
||||||
{
|
{
|
||||||
vector<string> names;
|
vector<string> names;
|
||||||
|
|
||||||
|
if (exists(path))
|
||||||
|
{
|
||||||
for (auto &entry : directory_iterator(path))
|
for (auto &entry : directory_iterator(path))
|
||||||
{
|
{
|
||||||
if (entry.is_directory())
|
if (entry.is_directory())
|
||||||
|
@ -90,6 +90,7 @@ vector<string> lsDirsInDir(const string &path)
|
||||||
names.push_back(entry.path().filename().string());
|
names.push_back(entry.path().filename().string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sort(names.begin(), names.end());
|
sort(names.begin(), names.end());
|
||||||
|
|
||||||
|
@ -112,7 +113,11 @@ void enforceMaxClips(const string &dirPath, shared_t *share)
|
||||||
{
|
{
|
||||||
auto names = lsDirsInDir(dirPath);
|
auto names = lsDirsInDir(dirPath);
|
||||||
|
|
||||||
while ((names.size() * 3) > ((share->maxClips - 1) * 3))
|
// note: this function assumes all video clips are accompanied by
|
||||||
|
// .html and .jpg files of the same name, hence why it *3
|
||||||
|
// the max names in the directory and *3 the file deletion.
|
||||||
|
|
||||||
|
while (names.size() > ((share->maxClips - 1) * 3))
|
||||||
{
|
{
|
||||||
remove(string(cleanDir(dirPath) + "/" + names[0]).c_str());
|
remove(string(cleanDir(dirPath) + "/" + names[0]).c_str());
|
||||||
remove(string(cleanDir(dirPath) + "/" + names[1]).c_str());
|
remove(string(cleanDir(dirPath) + "/" + names[1]).c_str());
|
||||||
|
@ -233,7 +238,10 @@ bool rdConf(shared_t *share)
|
||||||
|
|
||||||
if (share->init)
|
if (share->init)
|
||||||
{
|
{
|
||||||
remove_all(share->buffDir.c_str());
|
if (exists(share->buffDir))
|
||||||
|
{
|
||||||
|
remove_all(share->buffDir);
|
||||||
|
}
|
||||||
|
|
||||||
share->init = false;
|
share->init = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::filesystem;
|
using namespace std::filesystem;
|
||||||
|
|
||||||
#define APP_VER "1.5.t8"
|
#define APP_VER "1.5.t9"
|
||||||
#define APP_NAME "Motion Watch"
|
#define APP_NAME "Motion Watch"
|
||||||
|
|
||||||
struct shared_t
|
struct shared_t
|
||||||
|
@ -76,7 +76,6 @@ string cleanDir(const string &path);
|
||||||
string parseForParam(const string &arg, int argc, char** argv, bool argOnly);
|
string parseForParam(const string &arg, int argc, char** argv, bool argOnly);
|
||||||
bool createDir(const string &dir);
|
bool createDir(const string &dir);
|
||||||
bool createDirTree(const string &full_path);
|
bool createDirTree(const string &full_path);
|
||||||
bool fileExists(const string& name);
|
|
||||||
void enforceMaxDays(const string &dirPath, shared_t *share);
|
void enforceMaxDays(const string &dirPath, shared_t *share);
|
||||||
void enforceMaxClips(const string &dirPath, shared_t *share);
|
void enforceMaxClips(const string &dirPath, shared_t *share);
|
||||||
void rdLine(const string ¶m, const string &line, string *value);
|
void rdLine(const string ¶m, const string &line, string *value);
|
||||||
|
|
|
@ -23,18 +23,21 @@ void detLog(const string &line, shared_t *share)
|
||||||
}
|
}
|
||||||
|
|
||||||
void enforceMaxLogSize(const string &filePath, shared_t *share)
|
void enforceMaxLogSize(const string &filePath, shared_t *share)
|
||||||
|
{
|
||||||
|
if (exists(filePath))
|
||||||
{
|
{
|
||||||
if (file_size(filePath) >= share->maxLogSize)
|
if (file_size(filePath) >= share->maxLogSize)
|
||||||
{
|
{
|
||||||
remove(filePath);
|
remove(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void initLogFile(const string &filePath, ofstream &fileObj)
|
void initLogFile(const string &filePath, ofstream &fileObj)
|
||||||
{
|
{
|
||||||
if (!fileObj.is_open())
|
if (!fileObj.is_open())
|
||||||
{
|
{
|
||||||
if (!fileExists(filePath))
|
if (!exists(filePath))
|
||||||
{
|
{
|
||||||
system(string("touch " + filePath).c_str());
|
system(string("touch " + filePath).c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,11 @@ void detectLoop(shared_t *share)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
detLog("no motion detected in file: " + fullPath + " removing it.", share);
|
detLog("no motion detected in file: " + fullPath + " removing it.", share);
|
||||||
remove(fullPath.c_str());
|
|
||||||
|
if (exists(fullPath))
|
||||||
|
{
|
||||||
|
remove(fullPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user