feat(core): add new remove functions

Now sasa can be removed not only by ID, but also by file path, tanzaku can also be removed by name and alias.
This commit is contained in:
2022-12-21 17:55:35 +03:00
parent 587415dc78
commit 6f02cdae10
3 changed files with 70 additions and 7 deletions
+19 -1
View File
@@ -149,7 +149,7 @@ int sasa_add(Sasahyou *sasahyou, const char *path) {
return 0;
}
int sasa_rem(Sasahyou *sasahyou, uint64_t sasa_id) {
int sasa_rem_by_id(Sasahyou *sasahyou, uint64_t sasa_id) {
if (sasa_id > sasahyou->size) {
fprintf(stderr, "Failed to remove sasa: target sasa does not exist\n");
return 1;
@@ -164,3 +164,21 @@ int sasa_rem(Sasahyou *sasahyou, uint64_t sasa_id) {
return 0;
}
int sasa_rem_by_path(Sasahyou *sasahyou, const char *path) {
for (uint64_t i = 0; i < sasahyou->size; i++) {
if (strcmp(sasahyou->contents[i].path, path) == 0) {
if (sasahyou->contents[i].id != 0) {
sasahyou->modified_ts = time(NULL);
sasahyou->contents[i].id = 0;
sasahyou->removed_cnt++;
return 0;
} else {
fprintf(stderr, "Failed to remove sasa: target sasa is already removed\n");
return 1;
}
}
}
fprintf(stderr, "Failed to remove sasa: target sasa does not exist\n");
return 1;
}