Browse Source

Resolves: #463774
Summary: index files for database should be deleted when db is deleted.
Fix Description: The callback ldbm_instance_post_delete_instance_entry_callback
is called when the backend instance is removed. In the callback, there was a
code to cleanup the primary db (id2entry.db#), but no other index files nor the
instance directory. Also, the code included a bug to get the instance
directory path. The proposed code gets the right instance directory path and
cleans up all the files in the directory, then removes the backend instance
directory.

Noriko Hosoi 17 năm trước cách đây
mục cha
commit
53f3ccb259
1 tập tin đã thay đổi với 42 bổ sung23 xóa
  1. 42 23
      ldap/servers/slapd/back-ldbm/ldbm_instance_config.c

+ 42 - 23
ldap/servers/slapd/back-ldbm/ldbm_instance_config.c

@@ -939,34 +939,53 @@ ldbm_instance_post_delete_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry*
         struct dblayer_private_env *pEnv = priv->dblayer_env; 
         if(pEnv) {
             PRDir *dirhandle = NULL;
-            char dbName[MAXPATHLEN*2];
-            char *dbNamep = NULL;
-            char *p;
-            int dbbasenamelen, dbnamelen;
-            int rc;
+            char inst_dir[MAXPATHLEN*2];
+            char *inst_dirp = NULL;
+
             if (inst->inst_dir_name == NULL){
                 dblayer_get_instance_data_dir(inst->inst_be);
             }    
-            dirhandle = PR_OpenDir(inst->inst_dir_name);
-            /* the db dir instance may have been removed already */
-            if (dirhandle){
-                dbNamep = dblayer_get_full_inst_dir(li, inst,
-                                                    dbName, MAXPATHLEN*2);
-                dbbasenamelen = strlen(dbNamep);
-                dbnamelen = dbbasenamelen + 14; /* "/id2entry.db#" + '\0' */
-                if (dbnamelen > MAXPATHLEN*2)
-                {
-                    dbNamep = (char *)slapi_ch_realloc(dbNamep, dbnamelen);
+            inst_dirp = dblayer_get_full_inst_dir(li, inst, 
+                                                  inst_dir, MAXPATHLEN*2);
+            if (NULL != inst_dirp) {
+                dirhandle = PR_OpenDir(inst_dirp);
+                /* the db dir instance may have been removed already */
+                if (dirhandle) {
+                    PRDirEntry *direntry = NULL;
+                    char *dbp = NULL;
+                    char *p = NULL;
+                    while (NULL != (direntry = PR_ReadDir(dirhandle,
+                                               PR_SKIP_DOT|PR_SKIP_DOT_DOT))) {
+                        int rc;
+                        if (!direntry->name)
+                            break;
+
+                        dbp = PR_smprintf("%s/%s", inst_dirp, direntry->name);
+                        if (NULL == dbp) {
+                            LDAPDebug (LDAP_DEBUG_ANY,
+                            "ldbm_instance_post_delete_instance_entry_callback:"
+                            " failed to generate db path: %s/%s\n",
+                            inst_dirp, direntry->name, 0);
+                            break;
+                        }
+
+                        p = strstr(dbp, LDBM_FILENAME_SUFFIX);
+                        if (NULL != p &&
+                            strlen(p) == strlen(LDBM_FILENAME_SUFFIX)) {
+                            rc = dblayer_db_remove(pEnv, dbp, 0);
+                        } else {
+                            rc = PR_Delete(dbp);
+                        }
+                        PR_ASSERT(rc == 0);
+                        PR_smprintf_free(dbp);
+                    }
+                    PR_CloseDir(dirhandle);                
                 }
-                p = dbNamep + dbbasenamelen;
-                sprintf(p, "%c%s%s", get_sep(dbNamep),
-                                     "id2entry", LDBM_FILENAME_SUFFIX);
-                rc = dblayer_db_remove(pEnv, dbName, 0);
-                PR_ASSERT(rc == 0);
-                if (dbNamep != dbName)
-                    slapi_ch_free_string(&dbNamep);
-                PR_CloseDir(dirhandle);                
+                PR_RmDir(inst_dirp);
             } /* non-null dirhandle */
+            if (inst_dirp != inst_dir) {
+                slapi_ch_free_string(&inst_dirp);
+            }
         } /* non-null pEnv */
     }