From f4298037cc33c83eac0e39b3866ed927fd3bde2f Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Wed, 13 Dec 2023 04:44:31 -0800 Subject: [PATCH] Fixed File Logging and Factory Reset --- Projects/la_mojo/build | 16 +++++++-------- lib/App/mojo/mojoBackend.cpp | 3 +++ .../object/objectFileLoggingService.cpp | 20 +++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index 70621108..1c676512 100755 --- a/Projects/la_mojo/build +++ b/Projects/la_mojo/build @@ -2,13 +2,13 @@ #make clean -e "CFG=Debug" -make -e "CFG=Debug" -j6 +#make -e "CFG=Debug" -j6 -#make clean -e "CFG=Debug86" -#make -e "CFG=Debug86" -j4 +make clean -e "CFG=Debug86" +make -e "CFG=Debug86" -j4 -#make clean -e "CFG=Release86" -#make -e "CFG=Release86" -j4 -#cd Release86 -#strip ./mojo -#cd .. +make clean -e "CFG=Release86" +make -e "CFG=Release86" -j4 +cd Release86 +strip ./mojo +cd .. diff --git a/lib/App/mojo/mojoBackend.cpp b/lib/App/mojo/mojoBackend.cpp index 78701522..5d3aabd9 100644 --- a/lib/App/mojo/mojoBackend.cpp +++ b/lib/App/mojo/mojoBackend.cpp @@ -475,6 +475,9 @@ int main( int argc, char *argv[] ){ }; fileCopy( "data/factory.db", tNAME ); chown( tNAME, tUSER, tGROUP ); + // delete reports cleanup + system("rm -R -f data/reports"); + mkdir( "data/reports", 0755 ); }; free( tNAME ); free( tUSER ); diff --git a/lib/components/object/objectFileLoggingService.cpp b/lib/components/object/objectFileLoggingService.cpp index db0dafd3..4a65b526 100644 --- a/lib/components/object/objectFileLoggingService.cpp +++ b/lib/components/object/objectFileLoggingService.cpp @@ -23,29 +23,27 @@ void objectFileLoggingService::logMessage( const char *Msg ){ char tB[MAX_PATH_LEN]; sprintf( tB, "%s.%d", m_pFileName, MAX_LOG_FILE_BACKUPS ); if( fileExist( tB ) ) unlink( tB ); - uint8_t ix = 0; - do{ + uint8_t ix = MAX_LOG_FILE_BACKUPS; + while( ix ){ char tZ[MAX_PATH_LEN]; - if ( ix ) { - sprintf( tB,"%s.%d", m_pFileName, ix++ ); - sprintf( tZ,"%s.%d", m_pFileName, ix++ ); + sprintf( tZ,"%s.%d", m_pFileName, ix ); + if ( ix - 1 ) { + sprintf( tB,"%s.%d", m_pFileName, ix - 1 ); } else { sprintf( tB,"%s", m_pFileName ); - sprintf( tZ,"%s.%d", m_pFileName, ++ix ); }; - rename( tB, tZ ); - }while( ix < MAX_LOG_FILE_BACKUPS ); + if( fileExist( tB ) ) rename( tB, tZ ); + ix--; + }; } else { unlink( m_pFileName ); }; }; FILE *FD; - FD = fopen( m_pFileName , "a+"); + FD = fopen( m_pFileName , "a+"); if( FD != NULL ) { fwrite( Msg, 1, strlen(Msg), FD ); fclose(FD); - } else { - printf( "Totally Lost\n" ); }; }; };