@@ -1110,7 +1110,7 @@ const char * config_parameters[] = {
11101110 .keys_number = 1,\
11111111 .overwrite = 0,\
11121112 .sort = 1,\
1113- .version_validation = 0 ,\
1113+ .version_validation = 1 ,\
11141114 .verbose = 0,\
11151115 .is_mz_table = 0,\
11161116 .binary_mode = 0,\
@@ -1192,6 +1192,23 @@ bool ldb_importation_config_parse(import_params_t * opt, char * line)
11921192 return true;
11931193}
11941194
1195+ //cmd_in take precedency of the global cfg
1196+ static void opt_add (const import_params_t * cmd_in , import_params_t * cfg )
1197+ {
1198+ import_params_t def = {.params = LDB_IMPORTATION_CONFIG_DEFAULT };
1199+ for (int i = 0 ; i < IMPORT_PARAMS_NUMBER ; i ++ )
1200+ {
1201+ if (i == IMPORT_PARAMS_NUMBER - 1 && strcmp (cmd_in -> params .tmp_path , def .params .tmp_path ))
1202+ {
1203+ strcpy (cfg -> params .tmp_path , cmd_in -> params .tmp_path );
1204+ }
1205+ else if (cmd_in -> params_arr [i ] > -1 )
1206+ {
1207+ cfg -> params_arr [i ] = cmd_in -> params_arr [i ];
1208+ }
1209+ }
1210+ }
1211+
11951212bool ldb_create_db_config_default (char * dbname )
11961213{
11971214 #define DEFAULT_CONFIG_STRING "GLOBAL: (VALIDATE_FIELDS=1, VALIDATE_VERSION=1, SORT=1, FILE_DEL=0, OVERWRITE=0, WFP=0, MZ=0, VERBOSE=0, THREADS=%d, COLLATE=0, MAX_RECORD=2048, MAX_RAM_PERCENT=50, TMP_PATH=/tmp)\n"\
@@ -1244,6 +1261,9 @@ static int load_import_config(ldb_importation_config_t * config, import_params_t
12441261 sprintf (config_path ,"%s%s.conf" , LDB_CFG_PATH , config -> dbname );
12451262 int result = -1 ;
12461263 bool found = false;
1264+ import_params_t def = {.params = LDB_IMPORTATION_CONFIG_DEFAULT };
1265+ config -> opt = def ;
1266+ common -> params = def .params ;
12471267
12481268 if (ldb_file_exists (config_path ))
12491269 {
@@ -1264,13 +1284,13 @@ static int load_import_config(ldb_importation_config_t * config, import_params_t
12641284 strncpy (table_test , line , separator - line );
12651285
12661286 const char global_def []= "GLOBAL" ;
1267- if (!strcmp (table_test , global_def ))
1287+ if (!strcmp (table_test , global_def ) && result < 0 ) // force global config on the top of the file
12681288 {
12691289 // if (config->opt.params.verbose)
12701290 // fprintf(stderr, "The table %s is defined at %s as GLOBAL, some parameter may be overwritten\n", config->table, config_path);
12711291
12721292 ldb_importation_config_parse (common , line + strlen (global_def ));
1273- config -> opt . params = common -> params ;
1293+ opt_add ( common , & config -> opt ) ;
12741294 }
12751295 else
12761296 {
@@ -1540,23 +1560,6 @@ struct ldb_importation_jobs_s
15401560 import_params_t * global_opt ;
15411561};
15421562
1543- //cmd_in take precedency of the global cfg
1544- static void opt_add (const import_params_t * cmd_in , import_params_t * cfg )
1545- {
1546- import_params_t def = {.params = LDB_IMPORTATION_CONFIG_DEFAULT };
1547- for (int i = 0 ; i < IMPORT_PARAMS_NUMBER ; i ++ )
1548- {
1549- if (i == IMPORT_PARAMS_NUMBER - 1 && strcmp (cmd_in -> params .tmp_path , def .params .tmp_path ))
1550- {
1551- strcpy (cfg -> params .tmp_path , cmd_in -> params .tmp_path );
1552- }
1553- else if (cmd_in -> params_arr [i ] > -1 )
1554- {
1555- cfg -> params_arr [i ] = cmd_in -> params_arr [i ];
1556- }
1557- }
1558- }
1559-
15601563static void recurse_directory (struct ldb_importation_jobs_s * jobs , char * name , char * father )
15611564{
15621565 DIR * dir ;
@@ -1609,9 +1612,9 @@ static void recurse_directory(struct ldb_importation_jobs_s * jobs, char *name,
16091612
16101613 /*dir of the job*/
16111614 snprintf (jobs -> job [jobs -> number ]-> path , LDB_MAX_PATH , "%s" , dirname (path ));
1615+
16121616 //load of the configuration of the table (if it is defined).
16131617 int sort = load_import_config (jobs -> job [jobs -> number ], jobs -> global_opt );
1614-
16151618 //force stdin command priority
16161619 opt_add (jobs -> user_opt , & jobs -> job [jobs -> number ]-> opt );
16171620
@@ -1862,6 +1865,8 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18621865 if (job .opt .params .version_validation && !version_present )
18631866 {
18641867 logger_basic ("Failed to validate version.json, check if it is present in %s and it has the correct format\n" , job .path );
1868+ logger_basic ("You can avoid this error by setting \"VALIDATE_VERSION = 0\" in the import configuration options\n" , job .path );
1869+
18651870 exit (EXIT_FAILURE );
18661871 }
18671872
@@ -1938,7 +1943,7 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
19381943 logger_basic ("Failed to validate version.json, check if it is present in %s and it has the correct format\n" , job .path );
19391944 exit (EXIT_FAILURE );
19401945 }
1941- //import_params_t global_opt_def = {.params = LDB_IMPORTATION_CONFIG_DEFAULT};
1946+
19421947 load_import_config (& job , & global_opt );
19431948 opt_add (& user_opt , & global_opt );
19441949 opt_add (& user_opt , & job .opt );
0 commit comments