summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Lewandowski <tomasz.lewandoski@delphi.com>2016-12-13 06:56:41 -0800
committerCosmin Cernat <cosmin.cernat@continental-corporation.com>2017-01-31 13:21:22 +0200
commita77ff5a032e07e9aea027bc9d1d606db6e2dd5fe (patch)
tree9153ad7a18e051528a880a91a85498e7d3693744
parentf6131b486efafbfbd6e595fdf3ca9e609e66ba41 (diff)
downloadpersistence-administrator-a77ff5a032e07e9aea027bc9d1d606db6e2dd5fe.tar.gz
Handle empty /file and /key directories in database resources configuration.
Change-Id: Ifcb2a6df81f53b700e61ccc5375486b65f958ee5 Signed-off-by: Tomasz Lewandowski <tomasz.lewandoski@delphi.com>
-rw-r--r--Administrator/src/ssw_pers_admin_resource_config_add.c89
1 files changed, 70 insertions, 19 deletions
diff --git a/Administrator/src/ssw_pers_admin_resource_config_add.c b/Administrator/src/ssw_pers_admin_resource_config_add.c
index 973bfca..dcb4509 100644
--- a/Administrator/src/ssw_pers_admin_resource_config_add.c
+++ b/Administrator/src/ssw_pers_admin_resource_config_add.c
@@ -1600,6 +1600,33 @@ static bool_t pas_conf_removeDataForApp(constpstr_t appID, bool_t bPrepareForNew
****************************** Folder (public, group, app) data related *****************************************
*****************************************************************************************************************/
+
+/**
+ * \brief Create json configuration file with default content in given destination.
+ * \param filePath [in] path where the file will be created
+ * \param appName [in] application name which will be put into json config file
+ * \return true for success, false other way
+ */
+static bool_t createDefaultContentJsonFile(constpstr_t filePath, constpstr_t appName)
+{
+ FILE * pFile;
+ pFile = fopen (filePath,"w");
+ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Json config file '"), DLT_STRING(filePath), DLT_STRING("' with default configuration name has been created."));
+ if (pFile != NULL)
+ {
+ fputs("{\n", pFile);
+ char buffer[PERSADMIN_MAX_PATH_LENGHT];
+ sprintf(buffer, " \"config_appl\": \"%s\",\n", appName);
+ fputs(buffer,pFile);
+ fputs(" \"version\": \"0.1.0\",\n", pFile);
+ fputs(" \"resources\": {} \n", pFile);
+ fputs("}\n", pFile);
+ fclose(pFile);
+ }
+ return true;
+}
+
+
/**
* \brief Get the context for the public/group/app's install folder
* \param destInstallFolder [in] pathname for the destination(install) folder
@@ -1611,7 +1638,10 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
{
bool_t bEverythingOK = true ;
size_t iIndex = 0 ;
-
+
+ pstr_t appName[PERSADMIN_MAX_PATH_LENGHT];
+ persadmin_get_filename(destInstallFolder, appName, PERSADMIN_MAX_PATH_LENGHT);
+
/*---------------------------------------------------------------------------------------------------------
get context for destination folder
---------------------------------------------------------------------------------------------------------*/
@@ -1622,15 +1652,15 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
(void)snprintf(psInstallFolderCtx_inout->sDestContext.sRctDB.pathname,
sizeof(psInstallFolderCtx_inout->sDestContext.sRctDB.pathname),
"%s/%s", destInstallFolder, PERS_ORG_RCT_NAME) ;
- psInstallFolderCtx_inout->sDestContext.sRctDB.handler = persComRctOpen(psInstallFolderCtx_inout->sDestContext.sRctDB.pathname, true) ;
+ psInstallFolderCtx_inout->sDestContext.sRctDB.handler = persComRctOpen(psInstallFolderCtx_inout->sDestContext.sRctDB.pathname, true) ;
if(psInstallFolderCtx_inout->sDestContext.sRctDB.handler >= 0)
- {
+ {
psInstallFolderCtx_inout->sDestContext.sRctDB.bIsAvailable = true ;
}
else
- {
+ {
bEverythingOK = false ;
- }
+ }
(void)snprintf(g_msg, sizeof(g_msg), "%s - persComRctOpen(%s) returned <%d>",
__FUNCTION__, psInstallFolderCtx_inout->sDestContext.sRctDB.pathname, psInstallFolderCtx_inout->sDestContext.sRctDB.handler) ;
DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg));
@@ -1656,6 +1686,7 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
sizeof(tab_sDestLocalDBsInfo[iIndex].psFileAvailability->pathname),
"%s/%s", destInstallFolder, tab_sDestLocalDBsInfo[iIndex].filename) ;
tab_sDestLocalDBsInfo[iIndex].psFileAvailability->handler = persComDbOpen(tab_sDestLocalDBsInfo[iIndex].psFileAvailability->pathname, true) ;
+
if(tab_sDestLocalDBsInfo[iIndex].psFileAvailability->handler >= 0)
{
tab_sDestLocalDBsInfo[iIndex].psFileAvailability->bIsAvailable = true ;
@@ -1669,7 +1700,6 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg));
}
}
-
/*---------------------------------------------------------------------------------------------------------
get context for source folders
---------------------------------------------------------------------------------------------------------*/
@@ -1688,7 +1718,7 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
tab_sSrcContextEntries[0].psFileAvailability = &psInstallFolderCtx_inout->sSrcContext.sInstallFolder ;
tab_sSrcContextEntries[1].psFileAvailability = &psInstallFolderCtx_inout->sSrcContext.sFiledataFolder ;
tab_sSrcContextEntries[2].psFileAvailability = &psInstallFolderCtx_inout->sSrcContext.sKeydataFolder ;
-
+
for(iIndex = 0 ; bEverythingOK && (iIndex < sizeof(tab_sSrcContextEntries)/sizeof(tab_sSrcContextEntries[0])) ; iIndex++)
{
(void)snprintf( tab_sSrcContextEntries[iIndex].psFileAvailability->pathname,
@@ -1699,11 +1729,22 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ;
}
else
- {
- tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ;
+ {
+ tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ;
if(tab_sSrcContextEntries[iIndex].bPresenceIsMandatory)
- {
- bEverythingOK = false ;
+ {
+ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING("Folder with pathname: "), DLT_STRING( tab_sSrcContextEntries[iIndex].psFileAvailability->pathname ), DLT_STRING(" cannot be found! ") );
+ if ( persadmin_create_folder( tab_sSrcContextEntries[iIndex].psFileAvailability->pathname) == 0 )
+ {
+ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING("Empty folder has been created. Please be sure if it's ok!"));
+ tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ;
+ bEverythingOK = true;
+ }
+ else
+ {
+ DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING("Cannot create an empty folder."));
+ bEverythingOK = false ;
+ }
}
}
(void)snprintf(g_msg, sizeof(g_msg), "%s - %s <<%s>>", __FUNCTION__,
@@ -1720,9 +1761,9 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
{
{false, NIL,/* &psInstallFolderCtx_inout->sSrcContext.sRctFile */
PERSADM_CFG_RESOURCE_RCT_FILENAME, PersAdminCfgFileType_RCT, true},
- {false, NIL,/* &psInstallFolderCtx_inout->sSrcContext.sFactoryDefaultDataFile */
+ {false, NIL,/* &psInstallFolderCtx_inout->sSrcContext.sFactoryDefaultDataFile */
PERSADM_CFG_RESOURCE_ROOT_KEYDATA_FOLDER_NAME"/"PERSADM_CFG_RESOURCE_FACTORY_DEFAULT_KEYDATA_FILENAME, PersAdminCfgFileType_Database, true},
- {false, NIL,/* &psInstallFolderCtx_inout->sSrcContext.sConfigurableDefaultDataFile */
+ {false, NIL,/* &psInstallFolderCtx_inout->sSrcContext.sConfigurableDefaultDataFile */
PERSADM_CFG_RESOURCE_ROOT_KEYDATA_FOLDER_NAME"/"PERSADM_CFG_RESOURCE_CONFIG_KEYDEFAULT_DATA_FILENAME, PersAdminCfgFileType_Database, true},
{false, NIL,/* &psInstallFolderCtx_inout->sSrcContext.sInitialDataFile */
PERSADM_CFG_RESOURCE_ROOT_KEYDATA_FOLDER_NAME"/"PERSADM_CFG_RESOURCE_NON_DEFAULT_KEYDATA_FILENAME, PersAdminCfgFileType_Database, false},
@@ -1756,12 +1797,22 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg));
}
else
- {
- tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ;
- tab_sSrcContextEntries[iIndex].psFileAvailability->handler = -1 ;
+ {
if(tab_sSrcContextEntries[iIndex].bPresenceIsMandatory)
{
- bEverythingOK = false ;
+ createDefaultContentJsonFile(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, appName);
+ tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ;
+ tab_sSrcContextEntries[iIndex].psFileAvailability->handler = -1 ;
+ bEverythingOK = true;
+ }
+ else
+ {
+ tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ;
+ tab_sSrcContextEntries[iIndex].psFileAvailability->handler = -1 ;
+ if(tab_sSrcContextEntries[iIndex].bPresenceIsMandatory)
+ {
+ bEverythingOK = false ;
+ }
}
}
(void)snprintf(g_msg, sizeof(g_msg), "%s - %s <<%s>>", __FUNCTION__,
@@ -1783,11 +1834,11 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co
__FUNCTION__, bEverythingOK ? "OK" : "FAILED") ;
DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg));
}
- }
-
+ }
return bEverythingOK ;
}/*DG C8ISQP-ISQP Metric 10-SSW_Administrator_0001*/ /*DG C8ISQP-ISQP Metric 1-SSW_Administrator_0021*/ /*DG C8ISQP-ISQP Metric 6-SSW_Administrator_0022*/
+
/**
* \brief Close handlers, free dynamicaly allocated memory for the public/group/app's context
* \param psInstallFolderCtx_inout [inout] pointer to the public/group/app's context