@ohos-ports/lmdb 2.8.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +580 -0
  3. package/SECURITY.md +12 -0
  4. package/bin/download-prebuilds.js +15 -0
  5. package/binding.gyp +113 -0
  6. package/build/Release/lmdb.node +0 -0
  7. package/caching.js +212 -0
  8. package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -0
  9. package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -0
  10. package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -0
  11. package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -0
  12. package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -0
  13. package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -0
  14. package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -0
  15. package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -0
  16. package/dependencies/lmdb/libraries/liblmdb/lmdb.h +1817 -0
  17. package/dependencies/lmdb/libraries/liblmdb/mdb.c +12555 -0
  18. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -0
  19. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -0
  20. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -0
  21. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -0
  22. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -0
  23. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -0
  24. package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -0
  25. package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -0
  26. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -0
  27. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -0
  28. package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
  29. package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -0
  30. package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -0
  31. package/dependencies/lmdb/libraries/liblmdb/module.c +101 -0
  32. package/dependencies/lmdb/libraries/liblmdb/module.h +16 -0
  33. package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -0
  34. package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -0
  35. package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -0
  36. package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -0
  37. package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -0
  38. package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -0
  39. package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -0
  40. package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -0
  41. package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -0
  42. package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -0
  43. package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -0
  44. package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -0
  45. package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
  46. package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -0
  47. package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -0
  48. package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -0
  49. package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -0
  50. package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -0
  51. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -0
  52. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -0
  53. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -0
  54. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -0
  55. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -0
  56. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -0
  57. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -0
  58. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -0
  59. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -0
  60. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -0
  61. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -0
  62. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -0
  63. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -0
  64. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -0
  65. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -0
  66. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -0
  67. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -0
  68. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -0
  69. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -0
  70. package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -0
  71. package/dependencies/lz4/LICENSE +11 -0
  72. package/dependencies/lz4/lib/LICENSE +24 -0
  73. package/dependencies/lz4/lib/Makefile +225 -0
  74. package/dependencies/lz4/lib/README.md +169 -0
  75. package/dependencies/lz4/lib/dll/example/Makefile +63 -0
  76. package/dependencies/lz4/lib/dll/example/README.md +69 -0
  77. package/dependencies/lz4/lib/dll/example/fullbench-dll.sln +25 -0
  78. package/dependencies/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
  79. package/dependencies/lz4/lib/dll/liblz4.def +62 -0
  80. package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -0
  81. package/dependencies/lz4/lib/liblz4.pc.in +14 -0
  82. package/dependencies/lz4/lib/lz4.c +2722 -0
  83. package/dependencies/lz4/lib/lz4.h +842 -0
  84. package/dependencies/lz4/lib/lz4file.c +311 -0
  85. package/dependencies/lz4/lib/lz4file.h +93 -0
  86. package/dependencies/lz4/lib/lz4frame.c +2078 -0
  87. package/dependencies/lz4/lib/lz4frame.h +692 -0
  88. package/dependencies/lz4/lib/lz4frame_static.h +47 -0
  89. package/dependencies/lz4/lib/lz4hc.c +1631 -0
  90. package/dependencies/lz4/lib/lz4hc.h +413 -0
  91. package/dependencies/lz4/lib/xxhash.c +1030 -0
  92. package/dependencies/lz4/lib/xxhash.h +328 -0
  93. package/dependencies/v8/v8-fast-api-calls-v16.h +791 -0
  94. package/dependencies/v8/v8-fast-api-calls.h +888 -0
  95. package/dict/dict.txt +1 -0
  96. package/dict/dict2.txt +1 -0
  97. package/dist/index.cjs +2950 -0
  98. package/dist/index.cjs.map +1 -0
  99. package/index.d.cts +420 -0
  100. package/index.d.ts +450 -0
  101. package/index.js +38 -0
  102. package/keys.js +116 -0
  103. package/level.js +27 -0
  104. package/native.js +85 -0
  105. package/node-index.js +32 -0
  106. package/open.js +448 -0
  107. package/package.json +124 -0
  108. package/read.js +833 -0
  109. package/rollup.config.js +12 -0
  110. package/src/compression.cpp +225 -0
  111. package/src/cursor.cpp +395 -0
  112. package/src/dbi.cpp +382 -0
  113. package/src/env.cpp +1030 -0
  114. package/src/lmdb-js.cpp +64 -0
  115. package/src/lmdb-js.h +633 -0
  116. package/src/misc.cpp +593 -0
  117. package/src/ordered-binary.cpp +46 -0
  118. package/src/txn.cpp +210 -0
  119. package/src/v8-functions.cpp +170 -0
  120. package/src/windows.c +35 -0
  121. package/src/writer.cpp +537 -0
  122. package/util/RangeIterable.js +236 -0
  123. package/util/set-optional-deps.cjs +14 -0
  124. package/util/when.js +8 -0
  125. package/write.js +912 -0
@@ -0,0 +1,55 @@
1
+ .TH MDB_COPY 1 "2014/07/01" "LMDB 0.9.14"
2
+ .\" Copyright 2012-2021 Howard Chu, Symas Corp. All Rights Reserved.
3
+ .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4
+ .SH NAME
5
+ mdb_copy \- LMDB environment copy tool
6
+ .SH SYNOPSIS
7
+ .B mdb_copy
8
+ [\c
9
+ .BR \-V ]
10
+ [\c
11
+ .BR \-c ]
12
+ [\c
13
+ .BR \-n ]
14
+ .B srcpath
15
+ [\c
16
+ .BR dstpath ]
17
+ .SH DESCRIPTION
18
+ The
19
+ .B mdb_copy
20
+ utility copies an LMDB environment. The environment can
21
+ be copied regardless of whether it is currently in use.
22
+ No lockfile is created, since it gets recreated at need.
23
+
24
+ If
25
+ .I dstpath
26
+ is specified it must be the path of an empty directory
27
+ for storing the backup. Otherwise, the backup will be
28
+ written to stdout.
29
+
30
+ .SH OPTIONS
31
+ .TP
32
+ .BR \-V
33
+ Write the library version number to the standard output, and exit.
34
+ .TP
35
+ .BR \-c
36
+ Compact while copying. Only current data pages will be copied; freed
37
+ or unused pages will be omitted from the copy. This option will
38
+ slow down the backup process as it is more CPU-intensive.
39
+ Currently it fails if the environment has suffered a page leak.
40
+ .TP
41
+ .BR \-n
42
+ Open LDMB environment(s) which do not use subdirectories.
43
+
44
+ .SH DIAGNOSTICS
45
+ Exit status is zero if no errors occur.
46
+ Errors result in a non-zero exit status and
47
+ a diagnostic message being written to standard error.
48
+ .SH CAVEATS
49
+ This utility can trigger significant file size growth if run
50
+ in parallel with write transactions, because pages which they
51
+ free during copying cannot be reused until the copy is done.
52
+ .SH "SEE ALSO"
53
+ .BR mdb_stat (1)
54
+ .SH AUTHOR
55
+ Howard Chu of Symas Corporation <http://www.symas.com>
@@ -0,0 +1,82 @@
1
+ /* mdb_copy.c - memory-mapped database backup tool */
2
+ /*
3
+ * Copyright 2012-2021 Howard Chu, Symas Corp.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted only as authorized by the OpenLDAP
8
+ * Public License.
9
+ *
10
+ * A copy of this license is available in the file LICENSE in the
11
+ * top-level directory of the distribution or, alternatively, at
12
+ * <http://www.OpenLDAP.org/license.html>.
13
+ */
14
+ #ifdef _WIN32
15
+ #include <windows.h>
16
+ #define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
17
+ #else
18
+ #define MDB_STDOUT 1
19
+ #endif
20
+ #include <stdio.h>
21
+ #include <stdlib.h>
22
+ #include <signal.h>
23
+ #include "lmdb.h"
24
+
25
+ static void
26
+ sighandle(int sig)
27
+ {
28
+ }
29
+
30
+ int main(int argc,char * argv[])
31
+ {
32
+ int rc;
33
+ MDB_env *env;
34
+ const char *progname = argv[0], *act;
35
+ unsigned flags = MDB_RDONLY;
36
+ unsigned cpflags = 0;
37
+
38
+ for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
39
+ if (argv[1][1] == 'n' && argv[1][2] == '\0')
40
+ flags |= MDB_NOSUBDIR;
41
+ else if (argv[1][1] == 'c' && argv[1][2] == '\0')
42
+ cpflags |= MDB_CP_COMPACT;
43
+ else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
44
+ printf("%s\n", MDB_VERSION_STRING);
45
+ exit(0);
46
+ } else
47
+ argc = 0;
48
+ }
49
+
50
+ if (argc<2 || argc>3) {
51
+ fprintf(stderr, "usage: %s [-V] [-c] [-n] srcpath [dstpath]\n", progname);
52
+ exit(EXIT_FAILURE);
53
+ }
54
+
55
+ #ifdef SIGPIPE
56
+ signal(SIGPIPE, sighandle);
57
+ #endif
58
+ #ifdef SIGHUP
59
+ signal(SIGHUP, sighandle);
60
+ #endif
61
+ signal(SIGINT, sighandle);
62
+ signal(SIGTERM, sighandle);
63
+
64
+ act = "opening environment";
65
+ rc = mdb_env_create(&env);
66
+ if (rc == MDB_SUCCESS) {
67
+ rc = mdb_env_open(env, argv[1], flags, 0600);
68
+ }
69
+ if (rc == MDB_SUCCESS) {
70
+ act = "copying";
71
+ if (argc == 2)
72
+ rc = mdb_env_copyfd2(env, MDB_STDOUT, cpflags);
73
+ else
74
+ rc = mdb_env_copy2(env, argv[2], cpflags);
75
+ }
76
+ if (rc)
77
+ fprintf(stderr, "%s: %s failed, error %d (%s)\n",
78
+ progname, act, rc, mdb_strerror(rc));
79
+ mdb_env_close(env);
80
+
81
+ return rc ? EXIT_FAILURE : EXIT_SUCCESS;
82
+ }
@@ -0,0 +1,75 @@
1
+ .TH MDB_DUMP 1 "2015/09/30" "LMDB 0.9.17"
2
+ .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3
+ .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4
+ .SH NAME
5
+ mdb_dump \- LMDB environment export tool
6
+ .SH SYNOPSIS
7
+ .B mdb_dump
8
+ [\c
9
+ .BR \-V ]
10
+ [\c
11
+ .BI \-f \ file\fR]
12
+ [\c
13
+ .BR \-l ]
14
+ [\c
15
+ .BR \-n ]
16
+ [\c
17
+ .BR \-p ]
18
+ [\c
19
+ .BR \-a \ |
20
+ .BI \-s \ subdb\fR]
21
+ .BR \ envpath
22
+ .SH DESCRIPTION
23
+ The
24
+ .B mdb_dump
25
+ utility reads a database and writes its contents to the
26
+ standard output using a portable flat-text format
27
+ understood by the
28
+ .BR mdb_load (1)
29
+ utility.
30
+ .SH OPTIONS
31
+ .TP
32
+ .BR \-V
33
+ Write the library version number to the standard output, and exit.
34
+ .TP
35
+ .BR \-f \ file
36
+ Write to the specified file instead of to the standard output.
37
+ .TP
38
+ .BR \-l
39
+ List the databases stored in the environment. Just the
40
+ names will be listed, no data will be output.
41
+ .TP
42
+ .BR \-n
43
+ Dump an LMDB database which does not use subdirectories.
44
+ .TP
45
+ .BR \-p
46
+ If characters in either the key or data items are printing characters (as
47
+ defined by isprint(3)), output them directly. This option permits users to
48
+ use standard text editors and tools to modify the contents of databases.
49
+
50
+ Note: different systems may have different notions about what characters
51
+ are considered printing characters, and databases dumped in this manner may
52
+ be less portable to external systems.
53
+ .TP
54
+ .BR \-a
55
+ Dump all of the subdatabases in the environment.
56
+ .TP
57
+ .BR \-s \ subdb
58
+ Dump a specific subdatabase. If no database is specified, only the main database is dumped.
59
+ .SH DIAGNOSTICS
60
+ Exit status is zero if no errors occur.
61
+ Errors result in a non-zero exit status and
62
+ a diagnostic message being written to standard error.
63
+
64
+ Dumping and reloading databases that use user-defined comparison functions
65
+ will result in new databases that use the default comparison functions.
66
+ \fBIn this case it is quite likely that the reloaded database will be
67
+ damaged beyond repair permitting neither record storage nor retrieval.\fP
68
+
69
+ The only available workaround is to modify the source for the
70
+ .BR mdb_load (1)
71
+ utility to load the database using the correct comparison functions.
72
+ .SH "SEE ALSO"
73
+ .BR mdb_load (1)
74
+ .SH AUTHOR
75
+ Howard Chu of Symas Corporation <http://www.symas.com>
@@ -0,0 +1,319 @@
1
+ /* mdb_dump.c - memory-mapped database dump tool */
2
+ /*
3
+ * Copyright 2011-2021 Howard Chu, Symas Corp.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted only as authorized by the OpenLDAP
8
+ * Public License.
9
+ *
10
+ * A copy of this license is available in the file LICENSE in the
11
+ * top-level directory of the distribution or, alternatively, at
12
+ * <http://www.OpenLDAP.org/license.html>.
13
+ */
14
+ #include <stdio.h>
15
+ #include <errno.h>
16
+ #include <stdlib.h>
17
+ #include <string.h>
18
+ #include <ctype.h>
19
+ #include <unistd.h>
20
+ #include <signal.h>
21
+ #include "lmdb.h"
22
+
23
+ #ifdef _WIN32
24
+ #define Z "I"
25
+ #else
26
+ #define Z "z"
27
+ #endif
28
+
29
+ #define PRINT 1
30
+ static int mode;
31
+
32
+ typedef struct flagbit {
33
+ int bit;
34
+ char *name;
35
+ } flagbit;
36
+
37
+ flagbit dbflags[] = {
38
+ { MDB_REVERSEKEY, "reversekey" },
39
+ { MDB_DUPSORT, "dupsort" },
40
+ { MDB_INTEGERKEY, "integerkey" },
41
+ { MDB_DUPFIXED, "dupfixed" },
42
+ { MDB_INTEGERDUP, "integerdup" },
43
+ { MDB_REVERSEDUP, "reversedup" },
44
+ { 0, NULL }
45
+ };
46
+
47
+ static volatile sig_atomic_t gotsig;
48
+
49
+ static void dumpsig( int sig )
50
+ {
51
+ gotsig=1;
52
+ }
53
+
54
+ static const char hexc[] = "0123456789abcdef";
55
+
56
+ static void hex(unsigned char c)
57
+ {
58
+ putchar(hexc[c >> 4]);
59
+ putchar(hexc[c & 0xf]);
60
+ }
61
+
62
+ static void text(MDB_val *v)
63
+ {
64
+ unsigned char *c, *end;
65
+
66
+ putchar(' ');
67
+ c = v->mv_data;
68
+ end = c + v->mv_size;
69
+ while (c < end) {
70
+ if (isprint(*c)) {
71
+ if (*c == '\\')
72
+ putchar('\\');
73
+ putchar(*c);
74
+ } else {
75
+ putchar('\\');
76
+ hex(*c);
77
+ }
78
+ c++;
79
+ }
80
+ putchar('\n');
81
+ }
82
+
83
+ static void byte(MDB_val *v)
84
+ {
85
+ unsigned char *c, *end;
86
+
87
+ putchar(' ');
88
+ c = v->mv_data;
89
+ end = c + v->mv_size;
90
+ while (c < end) {
91
+ hex(*c++);
92
+ }
93
+ putchar('\n');
94
+ }
95
+
96
+ /* Dump in BDB-compatible format */
97
+ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name)
98
+ {
99
+ MDB_cursor *mc;
100
+ MDB_stat ms;
101
+ MDB_val key, data;
102
+ MDB_envinfo info;
103
+ unsigned int flags;
104
+ int rc, i;
105
+
106
+ rc = mdb_dbi_flags(txn, dbi, &flags);
107
+ if (rc) return rc;
108
+
109
+ rc = mdb_stat(txn, dbi, &ms);
110
+ if (rc) return rc;
111
+
112
+ rc = mdb_env_info(mdb_txn_env(txn), &info);
113
+ if (rc) return rc;
114
+
115
+ printf("VERSION=3\n");
116
+ printf("format=%s\n", mode & PRINT ? "print" : "bytevalue");
117
+ if (name)
118
+ printf("database=%s\n", name);
119
+ printf("type=btree\n");
120
+ printf("mapsize=%" Z "u\n", info.me_mapsize);
121
+ if (info.me_mapaddr)
122
+ printf("mapaddr=%p\n", info.me_mapaddr);
123
+ printf("maxreaders=%u\n", info.me_maxreaders);
124
+
125
+ if (flags & MDB_DUPSORT)
126
+ printf("duplicates=1\n");
127
+
128
+ for (i=0; dbflags[i].bit; i++)
129
+ if (flags & dbflags[i].bit)
130
+ printf("%s=1\n", dbflags[i].name);
131
+
132
+ printf("db_pagesize=%d\n", ms.ms_psize);
133
+ printf("HEADER=END\n");
134
+
135
+ rc = mdb_cursor_open(txn, dbi, &mc);
136
+ if (rc) return rc;
137
+
138
+ while ((rc = mdb_cursor_get(mc, &key, &data, MDB_NEXT) == MDB_SUCCESS)) {
139
+ if (gotsig) {
140
+ rc = EINTR;
141
+ break;
142
+ }
143
+ if (mode & PRINT) {
144
+ text(&key);
145
+ text(&data);
146
+ } else {
147
+ byte(&key);
148
+ byte(&data);
149
+ }
150
+ }
151
+ printf("DATA=END\n");
152
+ if (rc == MDB_NOTFOUND)
153
+ rc = MDB_SUCCESS;
154
+
155
+ return rc;
156
+ }
157
+
158
+ static void usage(char *prog)
159
+ {
160
+ fprintf(stderr, "usage: %s [-V] [-f output] [-l] [-n] [-p] [-a|-s subdb] dbpath\n", prog);
161
+ exit(EXIT_FAILURE);
162
+ }
163
+
164
+ int main(int argc, char *argv[])
165
+ {
166
+ int i, rc;
167
+ MDB_env *env;
168
+ MDB_txn *txn;
169
+ MDB_dbi dbi;
170
+ char *prog = argv[0];
171
+ char *envname;
172
+ char *subname = NULL;
173
+ int alldbs = 0, envflags = 0, list = 0;
174
+
175
+ if (argc < 2) {
176
+ usage(prog);
177
+ }
178
+
179
+ /* -a: dump main DB and all subDBs
180
+ * -s: dump only the named subDB
181
+ * -n: use NOSUBDIR flag on env_open
182
+ * -p: use printable characters
183
+ * -f: write to file instead of stdout
184
+ * -V: print version and exit
185
+ * (default) dump only the main DB
186
+ */
187
+ while ((i = getopt(argc, argv, "af:lnps:V")) != EOF) {
188
+ switch(i) {
189
+ case 'V':
190
+ printf("%s\n", MDB_VERSION_STRING);
191
+ exit(0);
192
+ break;
193
+ case 'l':
194
+ list = 1;
195
+ /*FALLTHROUGH*/;
196
+ case 'a':
197
+ if (subname)
198
+ usage(prog);
199
+ alldbs++;
200
+ break;
201
+ case 'f':
202
+ if (freopen(optarg, "w", stdout) == NULL) {
203
+ fprintf(stderr, "%s: %s: reopen: %s\n",
204
+ prog, optarg, strerror(errno));
205
+ exit(EXIT_FAILURE);
206
+ }
207
+ break;
208
+ case 'n':
209
+ envflags |= MDB_NOSUBDIR;
210
+ break;
211
+ case 'p':
212
+ mode |= PRINT;
213
+ break;
214
+ case 's':
215
+ if (alldbs)
216
+ usage(prog);
217
+ subname = optarg;
218
+ break;
219
+ default:
220
+ usage(prog);
221
+ }
222
+ }
223
+
224
+ if (optind != argc - 1)
225
+ usage(prog);
226
+
227
+ #ifdef SIGPIPE
228
+ signal(SIGPIPE, dumpsig);
229
+ #endif
230
+ #ifdef SIGHUP
231
+ signal(SIGHUP, dumpsig);
232
+ #endif
233
+ signal(SIGINT, dumpsig);
234
+ signal(SIGTERM, dumpsig);
235
+
236
+ envname = argv[optind];
237
+ rc = mdb_env_create(&env);
238
+ if (rc) {
239
+ fprintf(stderr, "mdb_env_create failed, error %d %s\n", rc, mdb_strerror(rc));
240
+ return EXIT_FAILURE;
241
+ }
242
+
243
+ if (alldbs || subname) {
244
+ mdb_env_set_maxdbs(env, 2);
245
+ }
246
+
247
+ rc = mdb_env_open(env, envname, envflags | MDB_RDONLY, 0664);
248
+ if (rc) {
249
+ fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
250
+ goto env_close;
251
+ }
252
+
253
+ rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
254
+ if (rc) {
255
+ fprintf(stderr, "mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc));
256
+ goto env_close;
257
+ }
258
+
259
+ rc = mdb_open(txn, subname, 0, &dbi);
260
+ if (rc) {
261
+ fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
262
+ goto txn_abort;
263
+ }
264
+
265
+ if (alldbs) {
266
+ MDB_cursor *cursor;
267
+ MDB_val key;
268
+ int count = 0;
269
+
270
+ rc = mdb_cursor_open(txn, dbi, &cursor);
271
+ if (rc) {
272
+ fprintf(stderr, "mdb_cursor_open failed, error %d %s\n", rc, mdb_strerror(rc));
273
+ goto txn_abort;
274
+ }
275
+ while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
276
+ char *str;
277
+ MDB_dbi db2;
278
+ if (memchr(key.mv_data, '\0', key.mv_size))
279
+ continue;
280
+ count++;
281
+ str = malloc(key.mv_size+1);
282
+ memcpy(str, key.mv_data, key.mv_size);
283
+ str[key.mv_size] = '\0';
284
+ rc = mdb_open(txn, str, 0, &db2);
285
+ if (rc == MDB_SUCCESS) {
286
+ if (list) {
287
+ printf("%s\n", str);
288
+ list++;
289
+ } else {
290
+ rc = dumpit(txn, db2, str);
291
+ if (rc)
292
+ break;
293
+ }
294
+ mdb_close(env, db2);
295
+ }
296
+ free(str);
297
+ if (rc) continue;
298
+ }
299
+ mdb_cursor_close(cursor);
300
+ if (!count) {
301
+ fprintf(stderr, "%s: %s does not contain multiple databases\n", prog, envname);
302
+ rc = MDB_NOTFOUND;
303
+ } else if (rc == MDB_NOTFOUND) {
304
+ rc = MDB_SUCCESS;
305
+ }
306
+ } else {
307
+ rc = dumpit(txn, dbi, subname);
308
+ }
309
+ if (rc && rc != MDB_NOTFOUND)
310
+ fprintf(stderr, "%s: %s: %s\n", prog, envname, mdb_strerror(rc));
311
+
312
+ mdb_close(env, dbi);
313
+ txn_abort:
314
+ mdb_txn_abort(txn);
315
+ env_close:
316
+ mdb_env_close(env);
317
+
318
+ return rc ? EXIT_FAILURE : EXIT_SUCCESS;
319
+ }
@@ -0,0 +1,84 @@
1
+ .TH MDB_LOAD 1 "2015/09/30" "LMDB 0.9.17"
2
+ .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3
+ .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4
+ .SH NAME
5
+ mdb_load \- LMDB environment import tool
6
+ .SH SYNOPSIS
7
+ .B mdb_load
8
+ [\c
9
+ .BR \-V ]
10
+ [\c
11
+ .BI \-f \ file\fR]
12
+ [\c
13
+ .BR \-n ]
14
+ [\c
15
+ .BI \-s \ subdb\fR]
16
+ [\c
17
+ .BR \-N ]
18
+ [\c
19
+ .BR \-T ]
20
+ .BR \ envpath
21
+ .SH DESCRIPTION
22
+ The
23
+ .B mdb_load
24
+ utility reads from the standard input and loads it into the
25
+ LMDB environment
26
+ .BR envpath .
27
+
28
+ The input to
29
+ .B mdb_load
30
+ must be in the output format specified by the
31
+ .BR mdb_dump (1)
32
+ utility or as specified by the
33
+ .B -T
34
+ option below.
35
+ .SH OPTIONS
36
+ .TP
37
+ .BR \-V
38
+ Write the library version number to the standard output, and exit.
39
+ .TP
40
+ .BR \-a
41
+ Append all records in the order they appear in the input. The input is assumed to already be
42
+ in correctly sorted order and no sorting or checking for redundant values will be performed.
43
+ This option must be used to reload data that was produced by running
44
+ .B mdb_dump
45
+ on a database that uses custom compare functions.
46
+ .TP
47
+ .BR \-f \ file
48
+ Read from the specified file instead of from the standard input.
49
+ .TP
50
+ .BR \-n
51
+ Load an LMDB database which does not use subdirectories.
52
+ .TP
53
+ .BR \-s \ subdb
54
+ Load a specific subdatabase. If no database is specified, data is loaded into the main database.
55
+ .TP
56
+ .BR \-N
57
+ Don't overwrite existing records when loading into an already existing database; just skip them.
58
+ .TP
59
+ .BR \-T
60
+ Load data from simple text files. The input must be paired lines of text, where the first
61
+ line of the pair is the key item, and the second line of the pair is its corresponding
62
+ data item.
63
+
64
+ A simple escape mechanism, where newline and backslash (\\) characters are special, is
65
+ applied to the text input. Newline characters are interpreted as record separators.
66
+ Backslash characters in the text will be interpreted in one of two ways: If the backslash
67
+ character precedes another backslash character, the pair will be interpreted as a literal
68
+ backslash. If the backslash character precedes any other character, the two characters
69
+ following the backslash will be interpreted as a hexadecimal specification of a single
70
+ character; for example, \\0a is a newline character in the ASCII character set.
71
+
72
+ For this reason, any backslash or newline characters that naturally occur in the text
73
+ input must be escaped to avoid misinterpretation by
74
+ .BR mdb_load .
75
+
76
+ .SH DIAGNOSTICS
77
+ Exit status is zero if no errors occur.
78
+ Errors result in a non-zero exit status and
79
+ a diagnostic message being written to standard error.
80
+
81
+ .SH "SEE ALSO"
82
+ .BR mdb_dump (1)
83
+ .SH AUTHOR
84
+ Howard Chu of Symas Corporation <http://www.symas.com>