mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 13:29: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:
parent
4740e274ed
commit
104d749513
26
src/menu.cpp
26
src/menu.cpp
@ -644,10 +644,11 @@ void Menu::setLinkIndex(int i) {
|
|||||||
void Menu::openPackagesFromDir(std::string path)
|
void Menu::openPackagesFromDir(std::string path)
|
||||||
{
|
{
|
||||||
DEBUG("Opening packages from directory: %s\n", path.c_str());
|
DEBUG("Opening packages from directory: %s\n", path.c_str());
|
||||||
readPackages(path);
|
if (readPackages(path)) {
|
||||||
#ifdef ENABLE_INOTIFY
|
#ifdef ENABLE_INOTIFY
|
||||||
monitors.emplace_back(new Monitor(path.c_str()));
|
monitors.emplace_back(new Monitor(path.c_str()));
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::openPackage(std::string path, bool order)
|
void Menu::openPackage(std::string path, bool order)
|
||||||
@ -716,23 +717,18 @@ void Menu::openPackage(std::string path, bool order)
|
|||||||
orderLinks();
|
orderLinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::readPackages(std::string parentDir)
|
bool Menu::readPackages(std::string const& parentDir)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp = opendir(parentDir.c_str());
|
||||||
struct dirent *dptr;
|
if (!dirp) {
|
||||||
vector<string> linkfiles;
|
return false;
|
||||||
|
}
|
||||||
dirp = opendir(parentDir.c_str());
|
|
||||||
if (!dirp)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while ((dptr = readdir(dirp))) {
|
|
||||||
char *c;
|
|
||||||
|
|
||||||
|
while (struct dirent *dptr = readdir(dirp)) {
|
||||||
if (dptr->d_type != DT_REG)
|
if (dptr->d_type != DT_REG)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
c = strrchr(dptr->d_name, '.');
|
char *c = strrchr(dptr->d_name, '.');
|
||||||
if (!c) /* File without extension */
|
if (!c) /* File without extension */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -750,6 +746,8 @@ void Menu::readPackages(std::string parentDir)
|
|||||||
|
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
orderLinks();
|
orderLinks();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_INOTIFY
|
#ifdef ENABLE_INOTIFY
|
||||||
|
@ -82,7 +82,7 @@ private:
|
|||||||
|
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
// Load all the .opk packages of the given directory
|
// Load all the .opk packages of the given directory
|
||||||
void readPackages(std::string parentDir);
|
bool readPackages(std::string const& parentDir);
|
||||||
#ifdef ENABLE_INOTIFY
|
#ifdef ENABLE_INOTIFY
|
||||||
std::vector<std::unique_ptr<Monitor>> monitors;
|
std::vector<std::unique_ptr<Monitor>> monitors;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user