bitcoinleveldb_file/filename.rs
1/*!
2 | File names used by DB code
3 |
4 */
5
6crate::ix!();
7
8//-------------------------------------------[.cpp/bitcoin/src/leveldb/db/filename.h]
9
10pub enum FileType {
11 LogFile,
12 DBLockFile,
13 TableFile,
14 DescriptorFile,
15 CurrentFile,
16 TempFile,
17 InfoLogFile // Either the current one, or an old one
18}
19
20//-------------------------------------------[.cpp/bitcoin/src/leveldb/db/filename.cc]
21
22pub fn make_file_name(
23 dbname: &String,
24 number: u64,
25 suffix: *const u8) -> String {
26
27 todo!();
28 /*
29 char buf[100];
30 snprintf(buf, sizeof(buf), "/%06llu.%s",
31 static_cast<unsigned long long>(number), suffix);
32 return dbname + buf;
33 */
34}
35
36/**
37 | Return the name of the log file with the
38 | specified number in the db named by "dbname".
39 |
40 | The result will be prefixed with "dbname".
41 |
42 */
43pub fn log_file_name(
44 dbname: &String,
45 number: u64) -> String {
46
47 todo!();
48 /*
49 assert(number > 0);
50 return MakeFileName(dbname, number, "log");
51 */
52}
53
54/**
55 | Return the name of the sstable with the
56 | specified number in the db named by "dbname".
57 |
58 | The result will be prefixed with "dbname".
59 |
60 */
61pub fn table_file_name(
62 dbname: &String,
63 number: u64) -> String {
64
65 todo!();
66 /*
67 assert(number > 0);
68 return MakeFileName(dbname, number, "ldb");
69 */
70}
71
72/**
73 | Return the legacy file name for an sstable with
74 | the specified number in the db named by
75 | "dbname". The result will be prefixed with
76 | "dbname".
77 */
78pub fn sst_table_file_name(
79 dbname: &String,
80 number: u64) -> String {
81
82 todo!();
83 /*
84 assert(number > 0);
85 return MakeFileName(dbname, number, "sst");
86 */
87}
88
89/**
90 | Return the name of the descriptor file for the
91 | db named by "dbname" and the specified
92 | incarnation number. The result will be
93 | prefixed with "dbname".
94 */
95pub fn descriptor_file_name(
96 dbname: &String,
97 number: u64) -> String {
98
99 todo!();
100 /*
101 assert(number > 0);
102 char buf[100];
103 snprintf(buf, sizeof(buf), "/MANIFEST-%06llu",
104 static_cast<unsigned long long>(number));
105 return dbname + buf;
106 */
107}
108
109/**
110 | Return the name of the current file.
111 | This file contains the name of the current
112 | manifest file.
113 |
114 | The result will be prefixed with "dbname".
115 |
116 */
117pub fn current_file_name(dbname: &String) -> String {
118
119 todo!();
120 /*
121 return dbname + "/CURRENT";
122 */
123}
124
125/**
126 | Return the name of the lock file for the
127 | db named by "dbname". The result will
128 | be prefixed with "dbname".
129 |
130 */
131pub fn lock_file_name(dbname: &String) -> String {
132
133 todo!();
134 /*
135 return dbname + "/LOCK";
136 */
137}
138
139/**
140 | Return the name of a temporary file owned by
141 | the db named "dbname".
142 |
143 | The result will be prefixed with "dbname".
144 */
145pub fn temp_file_name(
146 dbname: &String,
147 number: u64) -> String {
148
149 todo!();
150 /*
151 assert(number > 0);
152 return MakeFileName(dbname, number, "dbtmp");
153 */
154}
155
156/**
157 | Return the name of the info log file for
158 | "dbname".
159 |
160 */
161pub fn info_log_file_name(dbname: &String) -> String {
162
163 todo!();
164 /*
165 return dbname + "/LOG";
166 */
167}
168
169/**
170 | Return the name of the old info log file
171 | for "dbname".
172 |
173 */
174pub fn old_info_log_file_name(dbname: &String) -> String {
175
176 todo!();
177 /*
178 return dbname + "/LOG.old";
179 */
180}
181
182/**
183 | If filename is a leveldb file, store the type
184 | of the file in *type.
185 |
186 | The number encoded in the filename is stored in
187 | *number. If the filename was successfully
188 | parsed, returns true. Else return false.
189 |
190 ----------------------
191 | Owned filenames have the form:
192 | dbname/CURRENT
193 | dbname/LOCK
194 | dbname/LOG
195 | dbname/LOG.old
196 | dbname/MANIFEST-[0-9]+
197 | dbname/[0-9]+.(log|sst|ldb)
198 */
199pub fn parse_file_name(
200 filename: &String,
201 number: *mut u64,
202 ty: *mut FileType) -> bool {
203
204 todo!();
205 /*
206 Slice rest(filename);
207 if (rest == "CURRENT") {
208 *number = 0;
209 *type = kCurrentFile;
210 } else if (rest == "LOCK") {
211 *number = 0;
212 *type = kDBLockFile;
213 } else if (rest == "LOG" || rest == "LOG.old") {
214 *number = 0;
215 *type = kInfoLogFile;
216 } else if (rest.starts_with("MANIFEST-")) {
217 rest.remove_prefix(strlen("MANIFEST-"));
218 uint64_t num;
219 if (!ConsumeDecimalNumber(&rest, &num)) {
220 return false;
221 }
222 if (!rest.empty()) {
223 return false;
224 }
225 *type = kDescriptorFile;
226 *number = num;
227 } else {
228 // Avoid strtoull() to keep filename format independent of the
229 // current locale
230 uint64_t num;
231 if (!ConsumeDecimalNumber(&rest, &num)) {
232 return false;
233 }
234 Slice suffix = rest;
235 if (suffix == Slice(".log")) {
236 *type = kLogFile;
237 } else if (suffix == Slice(".sst") || suffix == Slice(".ldb")) {
238 *type = kTableFile;
239 } else if (suffix == Slice(".dbtmp")) {
240 *type = kTempFile;
241 } else {
242 return false;
243 }
244 *number = num;
245 }
246 return true;
247 */
248}
249