@@ -1036,7 +1036,7 @@ bool version_import(ldb_importation_config_t *job)
10361036 test_len -= (strlen (daily_date_i ) + strlen ("\"daily\":" ));
10371037 if (monthly_date_i )
10381038 test_len -= (strlen (monthly_date_i ) + strlen ("\"monthly\":" ));
1039- //exit if cannot find daily or monthly or there are am excess of characteres in the json
1039+ //exit if cannot find daily or monthly or there are an excess of characteres in the json
10401040 if ((!daily_date_i && !monthly_date_i ) || test_len > 10 )
10411041 {
10421042 logger_basic ("Failed to process version file: %s\n" , vf_import );
@@ -1072,7 +1072,7 @@ bool version_import(ldb_importation_config_t *job)
10721072 return false;
10731073 }
10741074
1075- fprintf (f , JSON_CONTENT , monthly_date_i == NULL ? "N/A" : monthly_date_i , daily_date_i == NULL ? "N/A" : daily_date_i );
1075+ fprintf (f , JSON_CONTENT , monthly_date_i == NULL ? "N/A" : monthly_date_i , daily_date_i == NULL ? "N/A" : daily_date_i );
10761076 fclose (f );
10771077 free (daily_date_i );
10781078 free (daily_date_o );
@@ -1176,7 +1176,7 @@ bool ldb_importation_config_parse(ldb_importation_config_t * config, char * line
11761176
11771177bool ldb_create_db_config_default (char * dbname )
11781178{
1179- char config [] = "GLOBAL: (VALIDATE_FIELDS=1, VALIDATE_VERSION=0 , SORT=1, FILE_DEL=0, OVERWRITE=0, WFP=0, MZ=0, VERBOSE=0, COLLATE=0, MAX_RECORD=2048, MAX_RAM_PERCENT=50, TMP_PATH=/tmp)\n"
1179+ char config [] = "GLOBAL: (VALIDATE_FIELDS=1, VALIDATE_VERSION=1 , SORT=1, FILE_DEL=0, OVERWRITE=0, WFP=0, MZ=0, VERBOSE=0, COLLATE=0, MAX_RECORD=2048, MAX_RAM_PERCENT=50, TMP_PATH=/tmp)\n"
11801180 "sources: (MZ=1, KEYS=1)\n"
11811181 "notices: (MZ=1, KEYS=1)\n"
11821182 "attribution: (KEYS=1, FIELDS=2)\n"
@@ -1413,13 +1413,6 @@ int ldb_import(ldb_importation_config_t * job)
14131413 int result = -1 ;
14141414 ldb_importation_config_t config = * job ;
14151415
1416- logger_set_level (config .opt .params .verbose );
1417- if (config .opt .params .version_validation && !version_import (& config ))
1418- {
1419- logger_basic ("Failed to validate version.json, check if it is present in %s and it has the correct format\n" , config .path );
1420- exit (EXIT_FAILURE );
1421- }
1422-
14231416 if (strstr (config .csv_path , ".mz" ))
14241417 config .opt .params .is_mz_table = true;
14251418 else
@@ -1807,7 +1800,7 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18071800
18081801 if (!ldb_database_exists (job .dbname ))
18091802 ldb_create_database (job .dbname );
1810-
1803+
18111804 struct ldb_importation_jobs_s jobs = {.job = NULL , .number = 0 , .common_opt = job .opt };
18121805 strcpy (jobs .dbname , job .dbname );
18131806 jobs .unsorted_index = 0 ;
@@ -1828,6 +1821,15 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18281821 if (!table && ldb_dir_exists (path ))
18291822 {
18301823 strcpy (job .path , path );
1824+ //check if the version file is present and update the kb version.
1825+ bool version_present = version_import (& job );
1826+ //abort the job if VERSION_VALIDATION is active and the json file is not present
1827+ if (job .opt .params .version_validation && !version_present )
1828+ {
1829+ logger_basic ("Failed to validate version.json, check if it is present in %s and it has the correct format\n" , job .path );
1830+ exit (EXIT_FAILURE );
1831+ }
1832+
18311833 recurse_directory (& jobs , path , NULL );
18321834 print_jobs (& jobs );
18331835 /* Process jobs*/
@@ -1882,6 +1884,13 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18821884 {
18831885 strcpy (job .path ,path );
18841886 }
1887+ bool version_present = version_import (& job );
1888+ //abort the job if VERSION_VALIDATION is active and the json file is not present
1889+ if (job .opt .params .version_validation && !version_present )
1890+ {
1891+ logger_basic ("Failed to validate version.json, check if it is present in %s and it has the correct format\n" , job .path );
1892+ exit (EXIT_FAILURE );
1893+ }
18851894 load_import_config (& job );
18861895 process_sectors (& job , threads_list );
18871896 }
0 commit comments