Skip to content

Commit a2315cb

Browse files
committed
add functions to make rootfs RW/RO everytime something needs to be saved
Signed-off-by: Vincent-FK <[email protected]>
1 parent 6cff159 commit a2315cb

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

RetroFE/Source/Collection/CollectionInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ bool CollectionInfo::Save()
8282
std::string file = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists/favorites.txt");
8383
Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file);
8484

85+
Utils::rootfsWritable();
86+
8587
std::ofstream filestream;
8688
try
8789
{
@@ -95,6 +97,7 @@ bool CollectionInfo::Save()
9597
if(ERROR_ALREADY_EXISTS != GetLastError())
9698
{
9799
Logger::write(Logger::ZONE_WARNING, "Collection", "Could not create directory " + dir);
100+
Utils::rootfsReadOnly();
98101
return false;
99102
}
100103
}
@@ -106,13 +109,15 @@ bool CollectionInfo::Save()
106109
#endif
107110
{
108111
Logger::write(Logger::ZONE_WARNING, "Collection", "Could not create directory " + dir);
112+
Utils::rootfsReadOnly();
109113
return false;
110114
}
111115
#endif
112116
}
113117
else if ( !(info.st_mode & S_IFDIR) )
114118
{
115119
Logger::write(Logger::ZONE_WARNING, "Collection", dir + " exists, but is not a directory.");
120+
Utils::rootfsReadOnly();
116121
return false;
117122
}
118123

@@ -138,6 +143,8 @@ bool CollectionInfo::Save()
138143
retval = false;
139144
}
140145
}
146+
147+
Utils::rootfsReadOnly();
141148

142149
return retval;
143150
}

RetroFE/Source/Collection/CollectionInfoBuilder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ bool CollectionInfoBuilder::createCollectionDirectory(std::string name)
9292
std::string filename = Utils::combinePath(collectionPath, "include.txt");
9393
std::cout << "Creating file \"" << filename << "\"" << std::endl;
9494

95+
Utils::rootfsWritable();
96+
9597
std::ofstream includeFile;
9698
includeFile.open(filename.c_str());
9799
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)
140142
std::ofstream menuFile;
141143
menuFile.open(filename.c_str());
142144
menuFile.close();
145+
146+
Utils::rootfsReadOnly();
143147

144148
return true;
145149
}

RetroFE/Source/Database/Configuration.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,12 @@ bool Configuration::exportCurrentLayout(std::string layoutFilePath, std::string
287287
Logger::write(Logger::ZONE_INFO, "Configuration", "Exporting layout \"" + layoutName +
288288
"\" in file \"" + layoutFilePath +"\"");
289289

290+
Utils::rootfsWritable();
290291
std::ofstream layoutFile;
291292
layoutFile.open(layoutFilePath.c_str());
292293
layoutFile << layoutName << std::endl;
293294
layoutFile.close();
295+
Utils::rootfsReadOnly();
294296

295297
return retVal;
296298
}

RetroFE/Source/Utility/Utils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ bool Utils::executeRawPath(const char *shellCmd)
292292
return retVal;
293293
}
294294

295+
bool Utils::rootfsWritable()
296+
{
297+
bool retVal = false;
298+
Logger::write(Logger::ZONE_DEBUG, "Utils", "Making rootfs writable with " + std::string(SHELL_CMD_ROOTFS_RW));
299+
retVal = executeRawPath(SHELL_CMD_ROOTFS_RW);
300+
return retVal;
301+
}
302+
303+
bool Utils::rootfsReadOnly()
304+
{
305+
bool retVal = false;
306+
Logger::write(Logger::ZONE_DEBUG, "Utils", "Making rootfs read only with " + std::string(SHELL_CMD_ROOTFS_RO));
307+
retVal = executeRawPath(SHELL_CMD_ROOTFS_RO);
308+
return retVal;
309+
}
310+
295311
int Utils::termfix(uint32_t ttyId){
296312
// Init tty file path
297313
char ttyFilePath[100];

RetroFE/Source/Utility/Utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <vector>
2020
#include <list>
2121
#include <stdint.h>
22+
23+
#define SHELL_CMD_ROOTFS_RW "rw"
24+
#define SHELL_CMD_ROOTFS_RO "ro"
25+
2226
class Utils
2327
{
2428
public:
@@ -45,6 +49,8 @@ class Utils
4549
static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4, std::string path5);
4650

4751
static bool executeRawPath(const char *shellCmd);
52+
static bool rootfsWritable();
53+
static bool rootfsReadOnly();
4854

4955
static int termfix(uint32_t ttyId);
5056
static int getVTid();

0 commit comments

Comments
 (0)