CError CModuleManager::store_module( const GUID &module_id ) { CInterfaceDefinition *interface_definition; CError CError; interface_definition = ( CInterfaceDefinition * ) get_interface_by_module_id( module_id ); if( !interface_definition ) { INTEGRA_TRACE_ERROR << "failed to lookup interface"; return CError::INPUT_ERROR; } if( interface_definition->get_file_path().empty() ) { INTEGRA_TRACE_ERROR << "Unknown interface file path"; return CError::INPUT_ERROR; } string module_storage_path = get_storage_path( *interface_definition ); if( module_storage_path.empty() ) { INTEGRA_TRACE_ERROR << "failed to get storage path"; return CError::INPUT_ERROR; } CError = CFileHelper::copy_file( interface_definition->get_file_path(), module_storage_path ); if( CError != CError::SUCCESS ) { return CError; } interface_definition->set_file_path( module_storage_path ); return CError::SUCCESS; }
CError CModuleManager::change_module_source( CInterfaceDefinition &interface_definition, CInterfaceDefinition::module_source new_source ) { /* sanity checks */ if( interface_definition.get_module_source() == CInterfaceDefinition::MODULE_SHIPPED_WITH_INTEGRA || new_source == CInterfaceDefinition::MODULE_SHIPPED_WITH_INTEGRA ) { return CError::INPUT_ERROR; } if( interface_definition.get_module_source() == new_source ) { return CError::INPUT_ERROR; } interface_definition.set_module_source( new_source ); string new_file_path = get_storage_path( interface_definition ); if( new_file_path.empty() ) { return CError::FAILED; } rename( interface_definition.get_file_path().c_str(), new_file_path.c_str() ); interface_definition.set_file_path( new_file_path ); return CError::SUCCESS; }
void remove_persistent_storage(const char *tag) { char buf[BUF_SIZE]; char path[BUF_SIZE]; get_storage_path(buf); if (snprintf(path, BUF_SIZE, "%s_%s", buf, tag) >= BUF_SIZE) path[BUF_SIZE - 1] = '\0'; unlink(path); }
FILE *get_persistent_storage(const char *tag, const char *mode) { char buf[BUF_SIZE]; char path[BUF_SIZE]; /* * The persistent storage with tag 'foo' for test 'bar' would * be named 'bar_persist_foo' */ get_storage_path(buf); if (snprintf(path, BUF_SIZE, "%s_%s", buf, tag) >= BUF_SIZE) path[BUF_SIZE - 1] = '\0'; return fopen(path, mode); }