Skip to content

Commit 5613449

Browse files
NeroBurnerJF002
authored andcommitted
Settings: more specific read and write mode
For each filesystem interaction be more specific if we want to read from the file or write to it. Doing a non-creating read on the loading of the settings file, otherwise an empty file could be created, and when reading that empty file for the initial settings I would expect an error (or random data) when reading.
1 parent dd47ba9 commit 5613449

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/components/settings/Settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void Settings::LoadSettingsFromFile() {
2626
SettingsData bufferSettings;
2727
lfs_file_t settingsFile;
2828

29-
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
29+
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDONLY) != LFS_ERR_OK) {
3030
return;
3131
}
3232
fs.FileRead(&settingsFile, reinterpret_cast<uint8_t*>(&bufferSettings), sizeof(settings));
@@ -39,7 +39,7 @@ void Settings::LoadSettingsFromFile() {
3939
void Settings::SaveSettingsToFile() {
4040
lfs_file_t settingsFile;
4141

42-
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
42+
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_WRONLY | LFS_O_CREAT) != LFS_ERR_OK) {
4343
return;
4444
}
4545
fs.FileWrite(&settingsFile, reinterpret_cast<uint8_t*>(&settings), sizeof(settings));

0 commit comments

Comments
 (0)