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

View File

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

View File

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

View File

@ -292,6 +292,22 @@ bool Utils::executeRawPath(const char *shellCmd)
return retVal; 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){ int Utils::termfix(uint32_t ttyId){
// Init tty file path // Init tty file path
char ttyFilePath[100]; char ttyFilePath[100];

View File

@ -19,6 +19,10 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <stdint.h> #include <stdint.h>
#define SHELL_CMD_ROOTFS_RW "rw"
#define SHELL_CMD_ROOTFS_RO "ro"
class Utils class Utils
{ {
public: 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 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 executeRawPath(const char *shellCmd);
static bool rootfsWritable();
static bool rootfsReadOnly();
static int termfix(uint32_t ttyId); static int termfix(uint32_t ttyId);
static int getVTid(); static int getVTid();