Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions utils/system_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/stat.h>
#include <time.h>
#include <fnmatch.h>
#include <strings.h>

/** Description: File present check.
*
Expand Down Expand Up @@ -172,19 +173,21 @@ int createDir(const char *dirname) {
return ret ;
}

/* Description: Use for clean Folder except file match with file_name.
/* Description: Use for clean Folder except file match with file_name and pdri_file_name.
* @param folder: Folder name
* @param file_name: File name pattern which are not to be deleted.
* @param file_name: Exact file name which is not to be deleted.
* @param pdri_file_name: Exact PDRI file name which is not to be deleted.
* @param model_name : This param is not in use in new design, but retaining this param for any future use case
Comment thread
satya200 marked this conversation as resolved.
* @return int : Fail RDK_API_FAILURE and Success RDK_API_SUCCESS
* */
int eraseFolderExcePramaFile(const char *folder, const char* file_name, const char *model_num)
int eraseFolderExceParamFile(const char *folder, const char* file_name, const char* pdri_file_name, const char *model_num)
{
int ret = RDK_API_FAILURE;
DIR *folder_fd = NULL;
struct dirent *dir = NULL;
char oldfile[512];

if (folder == NULL || file_name == NULL || model_num == NULL) {
if (folder == NULL || file_name == NULL || pdri_file_name == NULL || model_num == NULL) {
Comment thread
satya200 marked this conversation as resolved.
COMMONUTILITIES_ERROR("%s parameter is NULL\n", __FUNCTION__);
return ret;
}
Expand All @@ -193,10 +196,17 @@ int eraseFolderExcePramaFile(const char *folder, const char* file_name, const ch
COMMONUTILITIES_ERROR("%s : Unable to open folder=%s and file=%s\n", __FUNCTION__, folder, file_name);
Comment thread
satya200 marked this conversation as resolved.
return ret;
}

char file_hdr[256];
char pdri_hdr[256];

snprintf(file_hdr, sizeof(file_hdr), "%s.header", file_name);
snprintf(pdri_hdr, sizeof(pdri_hdr), "%s.header", pdri_file_name);

while((dir = readdir(folder_fd)) != NULL) {
if (dir->d_type == DT_DIR || (strstr(dir->d_name, file_name))) {
continue;
} else if(strstr(dir->d_name, model_num)) {
if (dir->d_type == DT_DIR || (strcasecmp(dir->d_name, file_name) == 0) || (strcasecmp(dir->d_name, pdri_file_name)==0) || strcasecmp(dir->d_name, file_hdr) == 0 || strcasecmp(dir->d_name, pdri_hdr) == 0) {
continue;
} else {
snprintf(oldfile, sizeof(oldfile), "%s/%s", folder, dir->d_name);
COMMONUTILITIES_INFO("%s Deleting old software file.%s\n", dir->d_name, oldfile);
unlink(oldfile);
Comment thread
satya200 marked this conversation as resolved.
Expand Down
3 changes: 1 addition & 2 deletions utils/system_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ int cmdExec(const char *cmd, char *output, unsigned int size_buff);
int getFileSize(const char *file_name);
int logFileData(const char *file_path);
int createDir(const char *dirname);
int eraseFolderExcePramaFile(const char *folder, const char* file_name, const char *model_num);

int eraseFolderExceParamFile(const char *folder, const char* file_name, const char* pdri_file_name,const char *model_num);
Comment thread
satya200 marked this conversation as resolved.
int createFile(const char *file_name);
int eraseTGZItemsMatching(const char *folder, const char* file_name);
size_t GetHwMacAddress( char *iface, char *pMac, size_t szBufSize );
Expand Down
Loading