Added a result system to keep better track of errors
This commit is contained in:
29
src/entry.c
29
src/entry.c
@@ -20,4 +20,31 @@ bool is_entry_id_valid(const char* entry_id) {
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Result get_entry_path(const char* entry_id, char** out_path) {
|
||||
*out_path = NULL;
|
||||
|
||||
if (!is_entry_id_valid(entry_id))
|
||||
return FAILURE;
|
||||
|
||||
return format(out_path, "%s/%s", ENTRY_POOL_DIR, entry_id);
|
||||
}
|
||||
|
||||
Result entry_exists(const char* entry_id, bool* out_exists) {
|
||||
*out_exists = false;
|
||||
|
||||
char* path;
|
||||
Result result = get_entry_path(entry_id, &path);
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
|
||||
struct stat st;
|
||||
bool exists = stat(path, &st) == 0 && S_ISDIR(st.st_mode);
|
||||
|
||||
free(path);
|
||||
|
||||
*out_exists = exists;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user