1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 17:51:34 +02:00

Don't use file system write permissions to determine "deletable"

Instead, consider the installation location non-deletable and the home
directory deletable. This makes the "deletable" property follow the
purpose of the directory rather than its implementation details.
This commit is contained in:
Maarten ter Huurne 2014-08-18 23:17:27 +02:00
parent fe790b1c8d
commit 5805d7889f
2 changed files with 9 additions and 8 deletions

View File

@ -818,21 +818,21 @@ void Menu::readLinks()
int correct = (i>sections.size() ? iSection : i); int correct = (i>sections.size() ? iSection : i);
string const& section = sections[correct]; string const& section = sections[correct];
readLinksOfSection(GMENU2X_SYSTEM_DIR "/sections/" + section, i); readLinksOfSection(
readLinksOfSection(GMenu2X::getHome() + "/sections/" + section, i); links[i], GMENU2X_SYSTEM_DIR "/sections/" + section, false);
readLinksOfSection(
links[i], GMenu2X::getHome() + "/sections/" + section, true);
} }
orderLinks(); orderLinks();
} }
void Menu::readLinksOfSection(std::string const& path, uint i) void Menu::readLinksOfSection(
vector<Link*>& links, string const& path, bool deletable)
{ {
DIR *dirp = opendir(path.c_str()); DIR *dirp = opendir(path.c_str());
if (!dirp) return; if (!dirp) return;
// Check whether link files in this directory could be deleted.
bool deletable = access(path.c_str(), W_OK) == 0;
while (struct dirent *dptr = readdir(dirp)) { while (struct dirent *dptr = readdir(dirp)) {
if (dptr->d_type != DT_REG) continue; if (dptr->d_type != DT_REG) continue;
string linkfile = path + '/' + dptr->d_name; string linkfile = path + '/' + dptr->d_name;
@ -842,7 +842,7 @@ void Menu::readLinksOfSection(std::string const& path, uint i)
link->setSize( link->setSize(
gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkWidth"],
gmenu2x->skinConfInt["linkHeight"]); gmenu2x->skinConfInt["linkHeight"]);
links[i].push_back(link); links.push_back(link);
} else { } else {
delete link; delete link;
} }

View File

@ -89,7 +89,8 @@ private:
#endif #endif
// Load all the links on the given section directory. // Load all the links on the given section directory.
void readLinksOfSection(std::string const& path, uint i); void readLinksOfSection(std::vector<Link*>& links,
std::string const& path, bool deletable);
void decSectionIndex(); void decSectionIndex();
void incSectionIndex(); void incSectionIndex();