depcheck to check non-zero file

This commit is contained in:
Vivek Kumar Dutta 2025-05-27 14:26:24 +05:30
parent 08cf6a9725
commit 6cbfa27973
No known key found for this signature in database
GPG key ID: 4E09F5AD8265FD4C
3 changed files with 28 additions and 1 deletions

View file

@ -348,7 +348,7 @@ static bool check_dependency(const char *conf_obj)
char *token, *saveptr;
for (token = strtok_r(conf_name, ",", &saveptr); token != NULL; token = strtok_r(NULL, ",", &saveptr)) {
if (!strcmp(pch, "file") && !file_exists(token))
if (!strcmp(pch, "file") && !bbfdm_file_nonzero(token))
return false;
if (!strcmp(pch, "ubus") && !dmubus_object_method_exists(token))

View file

@ -35,6 +35,22 @@ bool bbfdm_file_exists(const char *path)
return stat(path, &buffer) == 0;
}
bool bbfdm_file_nonzero(const char *path)
{
struct stat file_stats = {0};
int ret;
if (!path)
return false;
ret = stat(path, &file_stats);
if ((ret == 0) && (file_stats.st_size != 0)) {
return true;
}
return false;
}
bool bbfdm_is_regular_file(const char *path)
{
struct stat buffer;

View file

@ -36,6 +36,17 @@ bool bbfdm_folder_exists(const char *path);
*/
bool bbfdm_file_exists(const char *path);
/**
* @brief Check if a file exists at the given path.
*
* This function verifies the existence of a file at the specified path and also
* checks if file is not empty
*
* @param[in] path Path to the file.
* @return true if the file exists and non-empty, false otherwise.
*/
bool bbfdm_file_nonzero(const char *path);
/**
* @brief Check if a file is a regular file.
*