|
31 | 31 | #include <libgen.h> |
32 | 32 | #include <dirent.h> |
33 | 33 | #include <string.h> |
34 | | -#include <dlfcn.h> |
35 | 34 | #include <time.h> |
36 | 35 | #include "import.h" |
37 | 36 | #include "./ldb.h" |
|
44 | 43 | #include "collate.h" |
45 | 44 | #include "logger.h" |
46 | 45 | #include "ldb_error.h" |
47 | | - |
48 | | -#define DECODE_BASE64 8 |
49 | | -#define MAX_CSV_LINE_LEN 1024 |
| 46 | +#include "decode.h" |
50 | 47 | #define REC_SIZE_LEN 2 |
51 | 48 |
|
52 | 49 | pthread_mutex_t lock; |
53 | 50 |
|
54 | 51 | int max_threads = 0; |
55 | 52 | pthread_t * threads_list; |
56 | 53 | static long IGNORED_WFP_LN = sizeof(IGNORED_WFP); |
57 | | - |
58 | | -int (*decode) (int op, unsigned char *key, unsigned char *nonce, |
59 | | - const char *buffer_in, int buffer_in_len, unsigned char *buffer_out) = NULL; |
60 | | - |
61 | 54 | double progress_timer = 0; |
62 | 55 |
|
63 | | - |
64 | | -void * lib_handle = NULL; |
65 | | -bool ldb_import_decoder_lib_load(void) |
66 | | -{ |
67 | | - if (lib_handle != NULL) |
68 | | - return true; |
69 | | - /*set decode funtion pointer to NULL*/ |
70 | | - decode = NULL; |
71 | | - lib_handle = dlopen("libscanoss_encoder.so", RTLD_NOW); |
72 | | - char * err; |
73 | | - if (lib_handle) |
74 | | - { |
75 | | - log_info("Lib scanoss_encoder present\n"); |
76 | | - decode = dlsym(lib_handle, "scanoss_decode"); |
77 | | - if ((err = dlerror())) |
78 | | - { |
79 | | - log_info("%s\n", err); |
80 | | - return false; |
81 | | - } |
82 | | - return true; |
83 | | - } |
84 | | - |
85 | | - return false; |
86 | | -} |
87 | | - |
88 | | - |
89 | 56 | /** |
90 | 57 | * @brief Sort a csv file invokinkg a new process and executing a sort command |
91 | 58 | * |
@@ -521,6 +488,20 @@ int ldb_import_mz(ldb_importation_config_t * job) |
521 | 488 | if (!ldb_table_exists(job->dbname, job->table)) |
522 | 489 | ldb_create_table_new(job->dbname, job->table, 16, 0, job->opt.params.keys_number, LDB_TABLE_DEFINITION_MZ | |
523 | 490 | (job->opt.params.binary_mode ? LDB_TABLE_DEFINITION_ENCRYPTED : LDB_TABLE_DEFINITION_STANDARD)); |
| 491 | + else |
| 492 | + { |
| 493 | + /* Create table structure for bulk import (32-bit key) */ |
| 494 | + char db_table[LDB_MAX_NAME]; |
| 495 | + snprintf(db_table,LDB_MAX_NAME-1, "%s/%s", job->dbname, job->table); |
| 496 | + struct ldb_table oss_bulk = ldb_read_cfg(db_table); |
| 497 | + if (oss_bulk.keys < 1 || oss_bulk.definitions == LDB_TABLE_DEFINITION_UNDEFINED) |
| 498 | + { |
| 499 | + oss_bulk.keys = job->opt.params.keys_number; |
| 500 | + ldb_write_cfg(oss_bulk.db, oss_bulk.table, oss_bulk.key_ln, oss_bulk.rec_ln, oss_bulk.keys, |
| 501 | + job->opt.params.binary_mode ? LDB_TABLE_DEFINITION_MZ | LDB_TABLE_DEFINITION_ENCRYPTED : LDB_TABLE_DEFINITION_MZ | LDB_TABLE_DEFINITION_STANDARD); |
| 502 | + log_info("Table %s config file was updated\n", oss_bulk.table); |
| 503 | + } |
| 504 | + } |
524 | 505 |
|
525 | 506 | return (ldb_bin_join(job->csv_path, dest_path, job->opt.params.overwrite, false, job->opt.params.delete_after_import)); |
526 | 507 | } |
@@ -1491,7 +1472,7 @@ int ldb_import(ldb_importation_config_t * job) |
1491 | 1472 | { |
1492 | 1473 | pthread_mutex_lock(&lock); |
1493 | 1474 | if(!decode) |
1494 | | - ldb_import_decoder_lib_load(); |
| 1475 | + ldb_decoder_lib_load(); |
1495 | 1476 | pthread_mutex_unlock(&lock); |
1496 | 1477 | } |
1497 | 1478 |
|
@@ -1820,7 +1801,7 @@ bool ldb_import_command(char * dbtable, char * path, char * config) |
1820 | 1801 | import_params_t user_opt = {.params = LDB_IMPORTATION_CONFIG_UNDEFINED}; |
1821 | 1802 | import_params_t global_opt = {.params = LDB_IMPORTATION_CONFIG_UNDEFINED}; |
1822 | 1803 | ldb_importation_config_t job = {.opt.params = LDB_IMPORTATION_CONFIG_DEFAULT, .csv_path = "\0", .path = "\0"}; |
1823 | | - |
| 1804 | + |
1824 | 1805 | char *table = strrchr(dbtable, '/'); |
1825 | 1806 | if (table) |
1826 | 1807 | strncpy(job.dbname, dbtable, table - dbtable); |
@@ -1863,18 +1844,19 @@ bool ldb_import_command(char * dbtable, char * path, char * config) |
1863 | 1844 | strcpy(job.path, path); |
1864 | 1845 | //check if the version file is present and update the kb version. |
1865 | 1846 | bool version_present = version_import(&job); |
| 1847 | + |
| 1848 | + recurse_directory(&jobs, path, NULL); |
| 1849 | + opt_add(jobs.user_opt, jobs.global_opt); |
| 1850 | + opt_add(jobs.global_opt, jobs.user_opt); |
| 1851 | + |
1866 | 1852 | //abort the job if VERSION_VALIDATION is active and the json file is not present |
1867 | 1853 | if (job.opt.params.version_validation && !version_present) |
1868 | 1854 | { |
1869 | | - logger_basic("Failed to validate version.json, check if it is present in %s and it has the correct format\n", job.path); |
1870 | | - logger_basic("You can avoid this error by setting \"VALIDATE_VERSION = 0\" in the import configuration options\n", job.path); |
1871 | | - |
| 1855 | + fprintf(stderr, "Failed to validate version.json, check if it is present in %s and it has the correct format\n", job.path); |
| 1856 | + fprintf(stderr, "You can avoid this error by setting \"VALIDATE_VERSION = 0\" in the import configuration options\n"); |
1872 | 1857 | exit(EXIT_FAILURE); |
1873 | 1858 | } |
1874 | 1859 |
|
1875 | | - recurse_directory(&jobs, path, NULL); |
1876 | | - opt_add(jobs.user_opt, jobs.global_opt); |
1877 | | - opt_add(jobs.global_opt, jobs.user_opt); |
1878 | 1860 | print_jobs(&jobs); |
1879 | 1861 | max_threads = jobs.user_opt->params.threads; |
1880 | 1862 | fprintf(stderr, "Max threads set to: %d\n", max_threads); |
@@ -1938,18 +1920,19 @@ bool ldb_import_command(char * dbtable, char * path, char * config) |
1938 | 1920 | strcpy(job.path,path); |
1939 | 1921 | } |
1940 | 1922 |
|
| 1923 | + load_import_config(&job, &global_opt); |
| 1924 | + opt_add(&user_opt, &global_opt); |
| 1925 | + opt_add(&user_opt, &job.opt); |
| 1926 | + |
1941 | 1927 | bool version_present = version_import(&job); |
1942 | 1928 | //abort the job if VERSION_VALIDATION is active and the json file is not present |
1943 | 1929 | if (job.opt.params.version_validation && !version_present) |
1944 | 1930 | { |
1945 | | - logger_basic("Failed to validate version.json, check if it is present in %s and it has the correct format\n", job.path); |
| 1931 | + fprintf(stderr, "Failed to validate version.json, check if it is present in %s and it has the correct format\n", job.path); |
| 1932 | + fprintf(stderr, "You can avoid this error by setting \"VALIDATE_VERSION = 0\" in the import configuration options\n"); |
1946 | 1933 | exit(EXIT_FAILURE); |
1947 | 1934 | } |
1948 | 1935 |
|
1949 | | - load_import_config(&job, &global_opt); |
1950 | | - opt_add(&user_opt, &global_opt); |
1951 | | - opt_add(&user_opt, &job.opt); |
1952 | | - |
1953 | 1936 | max_threads = job.opt.params.threads; |
1954 | 1937 | fprintf(stderr, "Max threads set to: %d\n", max_threads); |
1955 | 1938 | pthread_mutex_init(&lock, NULL); |
|
0 commit comments