2024-07-02 01:44:07 +00:00
|
|
|
#include "../../include/package.h"
|
|
|
|
#include "../../include/error.h"
|
|
|
|
#include "../../include/util.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
size_t lm_package_data_keep_count(lm_pkg_data_t *data){
|
2024-07-02 01:44:07 +00:00
|
|
|
size_t index = 0;
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
if(NULL == data->keeps)
|
2024-07-02 01:44:07 +00:00
|
|
|
return index;
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
while(data->keeps[index] != NULL)
|
2024-07-02 01:44:07 +00:00
|
|
|
index++;
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
bool lm_package_data_keep_add(lm_pkg_data_t *data, char *path){
|
2024-07-02 01:44:07 +00:00
|
|
|
if(NULL == path){
|
|
|
|
lm_error_set(LM_ERR_ArgNULL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
if(NULL == data->keeps){
|
|
|
|
data->keeps = malloc(sizeof(char*)*2);
|
|
|
|
data->keeps[0] = strdup(path);
|
|
|
|
data->keeps[1] = NULL;
|
2024-07-02 01:44:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
size_t count = lm_package_data_depend_count(data);
|
|
|
|
data->keeps = realloc(data->depends, sizeof(char*)*(count+2));
|
|
|
|
data->keeps[count++] = strdup(path);
|
|
|
|
data->keeps[count] = NULL;
|
2024-07-02 01:44:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
bool lm_package_data_keep_contains(lm_pkg_data_t *data, char *path){
|
|
|
|
if(NULL == data || NULL == path){
|
2024-07-02 01:44:07 +00:00
|
|
|
lm_error_set(LM_ERR_ArgNULL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
if(NULL == data->keeps)
|
2024-07-02 01:44:07 +00:00
|
|
|
return false;
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
for(int i = 0; NULL != data->keeps[i]; i++)
|
|
|
|
if(eq(data->keeps[i], path))
|
2024-07-02 01:44:07 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2024-07-03 00:40:52 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
void lm_package_data_keep_free(lm_pkg_data_t *data){
|
|
|
|
if(NULL == data)
|
2024-07-03 00:40:52 +00:00
|
|
|
return;
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
if(NULL == data->keeps)
|
2024-07-03 00:40:52 +00:00
|
|
|
return;
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
for(int i = 0; data->keeps[i] != NULL; i++)
|
|
|
|
free(data->keeps[i]);
|
|
|
|
free(data->keeps);
|
2024-07-03 00:40:52 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
data->keeps = NULL;
|
2024-07-03 00:40:52 +00:00
|
|
|
}
|