@@ -638,7 +638,21 @@ static BOOL folder_empty_sf(db_conn_ptr &pdb, cpid_t cpid, const char *username,
638638}
639639
640640/* *
641- * @username: Used for SFOD permission checks and for adjusting readstates
641+ * @username: Used for SFOD permission checks and for adjusting readstates
642+ * @pb_partial: Indicator for the immediate caller that operation was not
643+ * fully carried out.
644+ * @pnormal_size: Indicator for the top-level callframe (e.g.
645+ * exmdb_server::empty_folder) how much to adjust the store
646+ * size.
647+ * @pfai_size: Indicator for the top-level callframe how much to adjust
648+ * the store size.
649+ * @pmessage_count: Indicator for immediate caller how many messages were purged.
650+ * Only relevant for the top-level folder; recursive calls use
651+ * %nullptr.
652+ * @pfolder_count: Indicator for immediate caller how many folders were purged.
653+ * Only relevant for the top-level folder.
654+ *
655+ * Obtain the MIDs present in a folder, then delete messages by MIDs.
642656 */
643657static BOOL folder_empty_folder (db_conn_ptr &pdb, cpid_t cpid,
644658 const char *username, uint64_t folder_id, unsigned int del_flags,
@@ -832,7 +846,7 @@ BOOL exmdb_server::delete_folder(const char *dir, cpid_t cpid,
832846 if (pstmt == nullptr )
833847 return FALSE ;
834848 if (pstmt.step () != SQLITE_ROW) {
835- /* Folder already gone */
849+ /* Search folder already gone; treat as success */
836850 *pb_result = TRUE ;
837851 return TRUE ;
838852 }
@@ -844,6 +858,7 @@ BOOL exmdb_server::delete_folder(const char *dir, cpid_t cpid,
844858 }
845859 auto dbase = pdb->lock_base_wr ();
846860 if (!b_search) {
861+ /* Ensure that the folder has no subordinate folders and no messages. */
847862 snprintf (sql_string, std::size (sql_string), " SELECT count(*) FROM "
848863 " folders WHERE parent_id=%llu" , LLU{fid_val});
849864 auto pstmt = pdb->prep (sql_string);
@@ -876,13 +891,13 @@ BOOL exmdb_server::delete_folder(const char *dir, cpid_t cpid,
876891 pstmt.finalize ();
877892 pdb->delete_dynamic (fid_val, dbase.get ());
878893 }
894+
879895 auto parent_id = common_util_get_folder_parent_fid (pdb->psqlite , fid_val);
880896 if (b_search) {
881897 /*
882- * Calling folder_empty_folder() is too much for search
883- * folders; it would delete not just the references but also
884- * the messages, which we do not want for
885- * exmdb_server::delete_folder.
898+ * Deleting (= shutdown of) a SF is different from emptying it.
899+ * SF have "hardlinks" (entries with same msgid as objects in
900+ * another folder), so emptying would mean purging messages.
886901 */
887902 snprintf (sql_string, std::size (sql_string), " DELETE FROM folders"
888903 " WHERE folder_id=%llu" , LLU{fid_val});
@@ -897,7 +912,7 @@ BOOL exmdb_server::delete_folder(const char *dir, cpid_t cpid,
897912 return FALSE ;
898913 snprintf (sql_string, std::size (sql_string), " DELETE FROM folders"
899914 " WHERE folder_id=%llu" , LLU{fid_val});
900- } else {
915+ } else { /* softdel */
901916 int account_id = get_account_id ();
902917 auto nt_time = rop_util_current_nttime ();
903918 uint64_t change_num = 0 ;
@@ -939,6 +954,8 @@ BOOL exmdb_server::delete_folder(const char *dir, cpid_t cpid,
939954 return FALSE ;
940955 pdb->notify_folder_deletion (parent_id, fid_val, *dbase);
941956 dbase.reset ();
957+
958+ /* Statistical updates for the parent folder */
942959 snprintf (sql_string, std::size (sql_string), " UPDATE folder_properties SET"
943960 " propval=propval+1 WHERE folder_id=%llu AND "
944961 " proptag=%u" , LLU{parent_id}, PR_DELETED_FOLDER_COUNT);
0 commit comments