From 4129b307b8e351fde53abc1592a155bfed4bbbf0 Mon Sep 17 00:00:00 2001 From: Cosmin Cernat Date: Tue, 31 Jan 2017 14:48:54 +0200 Subject: Adaption for [PATCH] Handle empty /file and /key directories in database resources configuration. Change-Id: Ic46a9d9a6fc9ebd0bc73dd09572eab7948761ccb Signed-off-by: Cosmin Cernat --- .../src/ssw_pers_admin_resource_config_add.c | 95 +++++++++++----------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/Administrator/src/ssw_pers_admin_resource_config_add.c b/Administrator/src/ssw_pers_admin_resource_config_add.c index dcb4509..297349e 100644 --- a/Administrator/src/ssw_pers_admin_resource_config_add.c +++ b/Administrator/src/ssw_pers_admin_resource_config_add.c @@ -11,6 +11,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Date Author Reason +* 2017-01-30 Cosmin Cernat Improve robustness of pas_conf_getContextInstallFolder function(). * 2016-06-02 Cosmin Cernat Bugzilla Bug 437: Moved WDOG re-triggering to glib loop * 2013.10.23 Ionut Ieremie CSP_WZ#6300: Installation of the default values in context of the custom keys not working * 2013.09.27 Ionut Ieremie CSP_WZ#5781: Fix memory leakage @@ -347,7 +348,7 @@ Helpers static bool_t pas_conf_unarchiveResourceFile(constpstr_t resourcePathname) ; static bool_t pas_conf_deleteFolderContent(pstr_t folderPathName, PersadminFilterMode_e eFilterMode) ; static sint_t pas_conf_filterResourcesList(pstr_t resourceID, bool_t bFilterOnlyNonDefault, bool_t bIsKeyType, pas_conf_listOfItems_s* const psListUnfiltered, pstr_t pListFiltered_out); - +static bool_t pas_conf_createDefaultContentJsonFile(constpstr_t filePath, constpstr_t appName) ; /****************************************************************************************************** ******************************** Implementation **************************************************** @@ -1607,22 +1608,24 @@ static bool_t pas_conf_removeDataForApp(constpstr_t appID, bool_t bPrepareForNew * \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) -{ +static bool_t pas_conf_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.")); + pFile = fopen (filePath,"w"); + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(__FUNCTION__), DLT_STRING("Json config file '"), + DLT_STRING(filePath), DLT_STRING("' with default configuration 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(buffer,pFile); fputs(" \"version\": \"0.1.0\",\n", pFile); fputs(" \"resources\": {} \n", pFile); fputs("}\n", pFile); - fclose(pFile); - } + fclose(pFile); + } return true; } @@ -1718,33 +1721,36 @@ 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, - sizeof(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname), + sizeof(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname), "%s%s", srcInstallFolder, tab_sSrcContextEntries[iIndex].filename) ; if(0 <= persadmin_check_if_file_exists(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, tab_sSrcContextEntries[iIndex].bIsFolder)) { - tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ; + tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ; } else - { - tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ; + { + tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ; if(tab_sSrcContextEntries[iIndex].bPresenceIsMandatory) - { - 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(LT_HDR), DLT_STRING(__FUNCTION__), + DLT_STRING(" - Folder with pathname: "), DLT_STRING( tab_sSrcContextEntries[iIndex].psFileAvailability->pathname ), DLT_STRING(" cannot be found! ") ); + + if (0 <= persadmin_create_folder( tab_sSrcContextEntries[iIndex].psFileAvailability->pathname)) { - 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; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(__FUNCTION__), + DLT_STRING(" - Empty folder has been created. Please be sure if it's ok!")); + + tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ; } else { - DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING("Cannot create an empty folder.")); + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_ERROR, DLT_STRING(LT_HDR), DLT_STRING(__FUNCTION__), DLT_STRING("- Cannot create an empty folder.")); bEverythingOK = false ; - } + } } } (void)snprintf(g_msg, sizeof(g_msg), "%s - %s <<%s>>", __FUNCTION__, @@ -1780,47 +1786,40 @@ static bool_t pas_conf_getContextInstallFolder(constpstr_t destInstallFolder, co for(iIndex = 0 ; bEverythingOK && (iIndex < sizeof(tab_sSrcContextEntries)/sizeof(tab_sSrcContextEntries[0])) ; iIndex++) { (void)snprintf( tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, - sizeof(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname), + sizeof(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname), "%s/%s", srcInstallFolder, tab_sSrcContextEntries[iIndex].filename) ; - if(0 <= persadmin_check_if_file_exists(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, tab_sSrcContextEntries[iIndex].bIsFolder)) + + if(tab_sSrcContextEntries[iIndex].bPresenceIsMandatory) { - tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ; - tab_sSrcContextEntries[iIndex].psFileAvailability->handler = - persAdmCfgFileOpen(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, tab_sSrcContextEntries[iIndex].eCfgFileType) ; + if(0 > persadmin_check_if_file_exists(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, tab_sSrcContextEntries[iIndex].bIsFolder)) + { + pas_conf_createDefaultContentJsonFile(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, appName); + } + + tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = true ; + tab_sSrcContextEntries[iIndex].psFileAvailability->handler = + persAdmCfgFileOpen(tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, tab_sSrcContextEntries[iIndex].eCfgFileType) ; + if(tab_sSrcContextEntries[iIndex].psFileAvailability->handler < 0) { bEverythingOK = false ; } - (void)snprintf(g_msg, sizeof(g_msg), "%s - persAdmCfgFileOpen(<%s>, %d) returned <%d>", + (void)snprintf(g_msg, sizeof(g_msg), "%s - persAdmCfgFileOpen(<%s>, %d) returned <%d>", __FUNCTION__, tab_sSrcContextEntries[iIndex].psFileAvailability->pathname, tab_sSrcContextEntries[iIndex].eCfgFileType, tab_sSrcContextEntries[iIndex].psFileAvailability->handler) ; - DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); } else - { - if(tab_sSrcContextEntries[iIndex].bPresenceIsMandatory) - { - 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 ; - } - } + { + tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable = false ; + tab_sSrcContextEntries[iIndex].psFileAvailability->handler = -1 ; } - (void)snprintf(g_msg, sizeof(g_msg), "%s - %s <<%s>>", __FUNCTION__, + + (void)snprintf(g_msg, sizeof(g_msg), "%s - %s <<%s>>", __FUNCTION__, tab_sSrcContextEntries[iIndex].psFileAvailability->bIsAvailable ? "Found" : "Not found", tab_sSrcContextEntries[iIndex].filename) ; DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); } - } /*--------------------------------------------------------------------------------------------------------- -- cgit v1.2.1