1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-26 05:07:42 +02:00

Don't start Monitor on non-existant paths

The check I removed earlier today was redundant for readPackages() but
not so much for the Monitor: it starts a thread and it logs an error,
both of which are better avoided when possible.

Also cleaned up implementation of readPackages() a bit.
This commit is contained in:
Maarten ter Huurne 2014-08-18 16:37:37 +02:00
parent 4740e274ed
commit 104d749513
2 changed files with 13 additions and 15 deletions

View File

@ -644,10 +644,11 @@ void Menu::setLinkIndex(int i) {
void Menu::openPackagesFromDir(std::string path)
{
DEBUG("Opening packages from directory: %s\n", path.c_str());
readPackages(path);
if (readPackages(path)) {
#ifdef ENABLE_INOTIFY
monitors.emplace_back(new Monitor(path.c_str()));
monitors.emplace_back(new Monitor(path.c_str()));
#endif
}
}
void Menu::openPackage(std::string path, bool order)
@ -716,23 +717,18 @@ void Menu::openPackage(std::string path, bool order)
orderLinks();
}
void Menu::readPackages(std::string parentDir)
bool Menu::readPackages(std::string const& parentDir)
{
DIR *dirp;
struct dirent *dptr;
vector<string> linkfiles;
dirp = opendir(parentDir.c_str());
if (!dirp)
return;
while ((dptr = readdir(dirp))) {
char *c;
DIR *dirp = opendir(parentDir.c_str());
if (!dirp) {
return false;
}
while (struct dirent *dptr = readdir(dirp)) {
if (dptr->d_type != DT_REG)
continue;
c = strrchr(dptr->d_name, '.');
char *c = strrchr(dptr->d_name, '.');
if (!c) /* File without extension */
continue;
@ -750,6 +746,8 @@ void Menu::readPackages(std::string parentDir)
closedir(dirp);
orderLinks();
return true;
}
#ifdef ENABLE_INOTIFY

View File

@ -82,7 +82,7 @@ private:
#ifdef HAVE_LIBOPK
// Load all the .opk packages of the given directory
void readPackages(std::string parentDir);
bool readPackages(std::string const& parentDir);
#ifdef ENABLE_INOTIFY
std::vector<std::unique_ptr<Monitor>> monitors;
#endif