From 06d479f14c557c361ec66f2a18c403fad8e543a9 Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Thu, 27 Apr 2023 15:50:58 +0200 Subject: [PATCH] Change input and results files permissions to user only --- src/HexoticPlugin/HexoticPlugin_Hexotic.cxx | 39 +++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx b/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx index 0a20fd9..9413d17 100644 --- a/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx +++ b/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx @@ -72,6 +72,9 @@ #include #include +#include +namespace boofs = boost::filesystem; + #define GMFVERSION GmfDouble #define GMFDIMENSION 3 @@ -87,6 +90,13 @@ static void removeFile( const TCollection_AsciiString& fileName ) } } +// change results files permissions to user only (using boost to be used without C++17) +static void chmodUserOnly(const char* filename) +{ + if (boofs::exists(filename)) + boofs::permissions(filename, boofs::remove_perms | boofs::group_all | boofs::others_all ); +} + //============================================================================= /*! * @@ -979,7 +989,9 @@ std::vector HexoticPlugin_Hexotic::writeSizeMapFile( MG_Hexotic_API // Close Files mgInput->GmfCloseMesh( verticesFileID ); + chmodUserOnly(myVerticesFile.c_str()); mgInput->GmfCloseMesh( solFileID ); + chmodUserOnly(mySolFile.c_str()); std::vector fileNames(2); fileNames[0] = myVerticesFile; @@ -1040,7 +1052,6 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, if ( aTmpDir.Value(aTmpDir.Length()) != '/' ) aTmpDir += '/'; #endif TCollection_AsciiString Hexotic_In(""), Hexotic_Out, Hexotic_SizeMap_Prefix; - TCollection_AsciiString modeFile_In( "chmod 666 " ), modeFile_Out( "chmod 666 " ); TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic"+getSuffix()+".log"; // log std::map aSmdsToHexoticIdMap; @@ -1093,10 +1104,7 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, if ( mgHexa.IsExecutable() ) { -#ifndef WIN32 - modeFile_In += Hexotic_In; - system( modeFile_In.ToCString() ); -#endif + chmodUserOnly(Hexotic_In.ToCString()); } aSmdsToHexoticIdMap.clear(); aHexoticIdToNodeMap.clear(); @@ -1107,17 +1115,15 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, std::string errStr; Ok = mgHexa.Compute( run_Hexotic, errStr ); // run + chmodUserOnly(aLogFileName.ToCString()); // -------------- // read a result // -------------- - if ( mgHexa.IsExecutable() && SMESH_File( Hexotic_Out.ToCString() ).exists() ) + if ( mgHexa.IsExecutable() ) { -#ifndef WIN32 - modeFile_Out += Hexotic_Out; - system( modeFile_Out.ToCString() ); -#endif + chmodUserOnly( Hexotic_Out.ToCString() ); } SMESH_MesherHelper aHelper( aMesh ); @@ -1211,7 +1217,6 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHel TCollection_AsciiString aTmpDir = _hexoticWorkingDirectory.c_str();//getTmpDir(); TCollection_AsciiString Hexotic_In, Hexotic_Out, Hexotic_SizeMap_Prefix; - TCollection_AsciiString modeFile_In( "chmod 666 " ), modeFile_Out( "chmod 666 " ); TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic"+getSuffix()+".log"; // log std::map aSmdsToHexoticIdMap; @@ -1239,10 +1244,7 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHel writeInput( &mgHexa, Hexotic_In.ToCString(), aHelper->GetMeshDS() ); if ( mgHexa.IsExecutable() ) { -#ifndef WIN32 - modeFile_In += Hexotic_In; - system( modeFile_In.ToCString() ); -#endif + chmodUserOnly( Hexotic_In.ToCString() ); } aSmdsToHexoticIdMap.clear(); aHexoticIdToNodeMap.clear(); @@ -1255,14 +1257,15 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHel std::string errStr; Ok = mgHexa.Compute( run_Hexotic, errStr ); // run + chmodUserOnly(aLogFileName.ToCString()); + // -------------- // read a result // -------------- - if ( mgHexa.IsExecutable() && SMESH_File( Hexotic_Out.ToCString() ).exists() ) + if ( mgHexa.IsExecutable() ) { - modeFile_Out += Hexotic_Out; - system( modeFile_Out.ToCString() ); + chmodUserOnly(Hexotic_Out.ToCString()); } Ok = Ok && readResult( &mgHexa, Hexotic_Out.ToCString(), this, aHelper ); -- 2.39.2