@@ -895,7 +895,8 @@ xmldb_clear(clixon_handle h,
895895 * @retval 0 OK
896896 * @retval -1 Error
897897 * @note Datastores / dirs are not actually deleted so that a backend after dropping priviliges
898- * can re-create them
898+ * can re-create them. It is not possible to drop priviliges when private candidate option
899+ * is enabled because candidate datastores are created dynamically for each session.
899900 */
900901int
901902xmldb_delete (clixon_handle h ,
@@ -910,17 +911,33 @@ xmldb_delete(clixon_handle h,
910911 int ndp ;
911912 int i ;
912913 char * regexp = NULL ;
914+ db_elmnt * de ;
915+ int del = 0 ;
913916
914917 clixon_debug (CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL , "%s" , db );
918+ if (clicon_option_bool (h , "CLICON_XMLDB_PRIVATE_CANDIDATE" )) {
919+ if ((de = xmldb_find (h , db )) != NULL )
920+ del = xmldb_candidate_get (de );
921+ }
915922 if (xmldb_clear (h , db ) < 0 )
916923 goto done ;
917924 if (xmldb_db2file (h , db , & filename ) < 0 )
918925 goto done ;
919- if (lstat (filename , & st ) == 0 )
920- if (truncate (filename , 0 ) < 0 ){
921- clixon_err (OE_DB , errno , "truncate %s" , filename );
922- goto done ;
926+ if (lstat (filename , & st ) == 0 ) {
927+ if (del ) {
928+ clixon_debug (CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL , "unlink %s" , filename );
929+ if (unlink (filename ) < 0 ) {
930+ clixon_err (OE_DB , errno , "unlink %s" , filename );
931+ goto done ;
932+ }
923933 }
934+ else {
935+ if (truncate (filename , 0 ) < 0 ){
936+ clixon_err (OE_DB , errno , "truncate %s" , filename );
937+ goto done ;
938+ }
939+ }
940+ }
924941 if (clicon_option_bool (h , "CLICON_XMLDB_MULTI" )){
925942 if (xmldb_db2subdir (h , db , & subdir ) < 0 )
926943 goto done ;
@@ -934,11 +951,20 @@ xmldb_delete(clixon_handle h,
934951 for (i = 0 ; i < ndp ; i ++ ){
935952 cbuf_reset (cb );
936953 cprintf (cb , "%s/%s" , subdir , dp [i ].d_name );
937- if (truncate (cbuf_get (cb ), 0 ) < 0 ){
938- clixon_err (OE_DB , errno , "truncate %s" , filename );
939- goto done ;
954+ if (del ) {
955+ clixon_debug (CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL , "unlink %s" , cbuf_get (cb ));
956+ if (unlink (cbuf_get (cb )) < 0 ) {
957+ clixon_err (OE_DB , errno , "unlink %s" , cbuf_get (cb ));
958+ goto done ;
959+ }
940960 }
941- }
961+ else {
962+ if (truncate (cbuf_get (cb ), 0 ) < 0 ){
963+ clixon_err (OE_DB , errno , "truncate %s" , cbuf_get (cb ));
964+ goto done ;
965+ }
966+ }
967+ }
942968 }
943969 }
944970 retval = 0 ;
0 commit comments