add functions to make rootfs RW/RO everytime something needs to be saved

Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
Vincent-FK 2020-11-04 08:36:51 +01:00
parent 6cff159abf
commit a2315cb143
5 changed files with 35 additions and 0 deletions

View File

@ -82,6 +82,8 @@ bool CollectionInfo::Save()
std::string file = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists/favorites.txt");
Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file);
Utils::rootfsWritable();
std::ofstream filestream;
try
{
@ -95,6 +97,7 @@ bool CollectionInfo::Save()
if(ERROR_ALREADY_EXISTS != GetLastError())
{
Logger::write(Logger::ZONE_WARNING, "Collection", "Could not create directory " + dir);
Utils::rootfsReadOnly();
return false;
}
}
@ -106,6 +109,7 @@ bool CollectionInfo::Save()
#endif
{
Logger::write(Logger::ZONE_WARNING, "Collection", "Could not create directory " + dir);
Utils::rootfsReadOnly();
return false;
}
#endif
@ -113,6 +117,7 @@ bool CollectionInfo::Save()
else if ( !(info.st_mode & S_IFDIR) )
{
Logger::write(Logger::ZONE_WARNING, "Collection", dir + " exists, but is not a directory.");
Utils::rootfsReadOnly();
return false;
}
@ -139,6 +144,8 @@ bool CollectionInfo::Save()
}
}
Utils::rootfsReadOnly();
return retval;
}

View File

@ -92,6 +92,8 @@ bool CollectionInfoBuilder::createCollectionDirectory(std::string name)
std::string filename = Utils::combinePath(collectionPath, "include.txt");
std::cout << "Creating file \"" << filename << "\"" << std::endl;
Utils::rootfsWritable();
std::ofstream includeFile;
includeFile.open(filename.c_str());
includeFile << "# Add a list of files to show on the menu (one filename per line, without the extension)." << std::endl;
@ -141,6 +143,8 @@ bool CollectionInfoBuilder::createCollectionDirectory(std::string name)
menuFile.open(filename.c_str());
menuFile.close();
Utils::rootfsReadOnly();
return true;
}
CollectionInfo *CollectionInfoBuilder::buildCollection(std::string name)

View File

@ -287,10 +287,12 @@ bool Configuration::exportCurrentLayout(std::string layoutFilePath, std::string
Logger::write(Logger::ZONE_INFO, "Configuration", "Exporting layout \"" + layoutName +
"\" in file \"" + layoutFilePath +"\"");
Utils::rootfsWritable();
std::ofstream layoutFile;
layoutFile.open(layoutFilePath.c_str());
layoutFile << layoutName << std::endl;
layoutFile.close();
Utils::rootfsReadOnly();
return retVal;
}

View File

@ -292,6 +292,22 @@ bool Utils::executeRawPath(const char *shellCmd)
return retVal;
}
bool Utils::rootfsWritable()
{
bool retVal = false;
Logger::write(Logger::ZONE_DEBUG, "Utils", "Making rootfs writable with " + std::string(SHELL_CMD_ROOTFS_RW));
retVal = executeRawPath(SHELL_CMD_ROOTFS_RW);
return retVal;
}
bool Utils::rootfsReadOnly()
{
bool retVal = false;
Logger::write(Logger::ZONE_DEBUG, "Utils", "Making rootfs read only with " + std::string(SHELL_CMD_ROOTFS_RO));
retVal = executeRawPath(SHELL_CMD_ROOTFS_RO);
return retVal;
}
int Utils::termfix(uint32_t ttyId){
// Init tty file path
char ttyFilePath[100];

View File

@ -19,6 +19,10 @@
#include <vector>
#include <list>
#include <stdint.h>
#define SHELL_CMD_ROOTFS_RW "rw"
#define SHELL_CMD_ROOTFS_RO "ro"
class Utils
{
public:
@ -45,6 +49,8 @@ public:
static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4, std::string path5);
static bool executeRawPath(const char *shellCmd);
static bool rootfsWritable();
static bool rootfsReadOnly();
static int termfix(uint32_t ttyId);
static int getVTid();