jcs
/subtext
/amendments
/301
bile: Add flags arg to bile_delete, make zeroing and purging optional
When deleting a bunch of records in a row, we can avoid writing out
a new map every time.
jcs made amendment 301 about 1 year ago
--- bile.c Sun Feb 5 09:37:19 2023
+++ bile.c Thu Feb 16 14:28:29 2023
@@ -399,7 +399,8 @@ bile_next_id(struct bile *bile, const OSType type)
}
short
-bile_delete(struct bile *bile, const OSType type, const unsigned long id)
+bile_delete(struct bile *bile, const OSType type, const unsigned long id,
+ const unsigned short flags)
{
static char zero[128] = { 0 };
struct bile_object *o;
@@ -420,21 +421,23 @@ bile_delete(struct bile *bile, const OSType type, cons
pos = o->pos;
size = o->size + BILE_OBJECT_SIZE;
- _bile_error = bile->last_error = SetFPos(bile->frefnum, fsFromStart,
- pos);
- if (_bile_error)
- return -1;
-
- while (size > 0) {
- wsize = MIN(128, size);
- size -= wsize;
-
- _bile_error = bile->last_error = FSWrite(bile->frefnum, &wsize,
- zero);
+ if (flags & BILE_DELETE_FLAG_ZERO) {
+ _bile_error = bile->last_error = SetFPos(bile->frefnum, fsFromStart,
+ pos);
if (_bile_error)
return -1;
+
+ while (size > 0) {
+ wsize = MIN(128, size);
+ size -= wsize;
+
+ _bile_error = bile->last_error = FSWrite(bile->frefnum, &wsize,
+ zero);
+ if (_bile_error)
+ return -1;
+ }
}
-
+
/*
* If this is the highest id of this type, store it so it won't get
* handed out again from bile_next_id
@@ -454,7 +457,7 @@ bile_delete(struct bile *bile, const OSType type, cons
sizeof(unsigned long));
/* bile_write wrote a new map for us */
- } else {
+ } else if (flags & BILE_DELETE_FLAG_PURGE) {
bile_write_map(bile);
if (_bile_error)
return -1;
--- bile.h Tue Nov 29 17:14:11 2022
+++ bile.h Thu Feb 16 14:26:36 2023
@@ -77,6 +77,9 @@ struct bile_object {
#define BILE_ERR_NEED_UPGRADE_1 -4000
#define BILE_ERR_BOGUS_OBJECT -4001
+#define BILE_DELETE_FLAG_ZERO (1 << 0)
+#define BILE_DELETE_FLAG_PURGE (1 << 1)
+
struct bile_highest_id {
OSType type;
unsigned long highest_id;
@@ -119,7 +122,7 @@ struct bile_object * bile_get_nth_of_type(struct bile
const unsigned long index, const OSType type);
unsigned long bile_next_id(struct bile *bile, const OSType type);
short bile_delete(struct bile *bile, const OSType type,
- const unsigned long id);
+ const unsigned long id, const unsigned short flags);
size_t bile_read_object(struct bile *bile,
const struct bile_object *o, void *data,
const size_t len);
--- board.c Sun Feb 5 09:43:02 2023
+++ board.c Thu Feb 16 14:30:26 2023
@@ -886,8 +886,10 @@ board_delete_post(struct session *s, struct board *boa
unsigned long *new_parent_post_ids;
if (thread->nposts == 1) {
- bile_delete(board->bile, BOARD_THREAD_RTYPE, thread->thread_id);
- bile_delete(board->bile, BOARD_POST_RTYPE, post->id);
+ bile_delete(board->bile, BOARD_THREAD_RTYPE, thread->thread_id,
+ 0);
+ bile_delete(board->bile, BOARD_POST_RTYPE, post->id,
+ BILE_DELETE_FLAG_PURGE);
return;
}
@@ -944,7 +946,8 @@ board_delete_post(struct session *s, struct board *boa
}
xfree(&data);
- bile_delete(board->bile, BOARD_POST_RTYPE, post->id);
+ bile_delete(board->bile, BOARD_POST_RTYPE, post->id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE);
bile_flush(board->bile, true);
return;
--- folder.c Sun Feb 5 10:30:25 2023
+++ folder.c Thu Feb 16 14:31:23 2023
@@ -947,7 +947,8 @@ folder_file_save(struct folder *folder, struct folder_
PtoCstr(new_name);
if (ret != 0) {
warn("FSRename(%s, 0, %s) failed: %d", temp_path, new_name, ret);
- bile_delete(folder->bile, FOLDER_FILE_RTYPE, file->id);
+ bile_delete(folder->bile, FOLDER_FILE_RTYPE, file->id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE);
file->id = 0;
xfree(&new_name);
return false;
@@ -964,7 +965,8 @@ folder_delete_file(struct session *s, struct folder *f
char *path = NULL;
short ret;
- bile_delete(folder->bile, FOLDER_FILE_RTYPE, file->id);
+ bile_delete(folder->bile, FOLDER_FILE_RTYPE, file->id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE);
bile_flush(folder->bile, true);
path = xmalloc(FILENAME_MAX, "folder_delete_file");
--- mail.c Sun Feb 5 10:33:32 2023
+++ mail.c Thu Feb 16 14:31:44 2023
@@ -535,7 +535,8 @@ mail_read(struct session *s, unsigned long id, short i
xfree(&reply_subject);
break;
case 'd':
- if (bile_delete(db->bile, DB_MESSAGE_RTYPE, msg.id) == 0)
+ if (bile_delete(db->bile, DB_MESSAGE_RTYPE, msg.id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE) == 0)
session_printf(s, "Deleted message {{B}}%d{{/B}}\r\n", idx);
else
session_printf(s, "Failed deleting message "
--- sysop.c Sun Feb 5 10:44:34 2023
+++ sysop.c Thu Feb 16 14:32:17 2023
@@ -432,7 +432,8 @@ motd_write:
old_motd = bile_get_nth_of_type(db->bile, 0,
DB_MOTD_RTYPE);
if (old_motd) {
- bile_delete(db->bile, DB_MOTD_RTYPE, old_motd->id);
+ bile_delete(db->bile, DB_MOTD_RTYPE, old_motd->id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE);
xfree(&old_motd);
}
bile_write(db->bile, DB_MOTD_RTYPE, new_id, motd,
--- user.c Sun Feb 5 10:55:59 2023
+++ user.c Thu Feb 16 14:33:06 2023
@@ -398,11 +398,13 @@ user_delete(struct user *user)
continue;
}
- bile_delete(db->bile, DB_MESSAGE_RTYPE, id);
+ bile_delete(db->bile, DB_MESSAGE_RTYPE, id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE);
/* don't increase n, the remaining messages will shift down */
}
/* delete the user */
- bile_delete(db->bile, DB_USER_RTYPE, user->id);
+ bile_delete(db->bile, DB_USER_RTYPE, user->id,
+ BILE_DELETE_FLAG_ZERO | BILE_DELETE_FLAG_PURGE);
}