1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*!
  | File names used by DB code
  |
  */

crate::ix!();

//-------------------------------------------[.cpp/bitcoin/src/leveldb/db/filename.h]

pub enum FileType {
    LogFile,
    DBLockFile,
    TableFile,
    DescriptorFile,
    CurrentFile,
    TempFile,
    InfoLogFile  // Either the current one, or an old one
}

//-------------------------------------------[.cpp/bitcoin/src/leveldb/db/filename.cc]

pub fn make_file_name(
        dbname: &String,
        number: u64,
        suffix: *const u8) -> String {
    
    todo!();
        /*
            char buf[100];
      snprintf(buf, sizeof(buf), "/%06llu.%s",
               static_cast<unsigned long long>(number), suffix);
      return dbname + buf;
        */
}

/**
  | Return the name of the log file with the
  | specified number in the db named by "dbname".
  | 
  | The result will be prefixed with "dbname".
  |
  */
pub fn log_file_name(
        dbname: &String,
        number: u64) -> String {
    
    todo!();
        /*
            assert(number > 0);
      return MakeFileName(dbname, number, "log");
        */
}

/**
  | Return the name of the sstable with the
  | specified number in the db named by "dbname".
  | 
  | The result will be prefixed with "dbname".
  |
  */
pub fn table_file_name(
        dbname: &String,
        number: u64) -> String {
    
    todo!();
        /*
            assert(number > 0);
      return MakeFileName(dbname, number, "ldb");
        */
}

/**
  | Return the legacy file name for an sstable with
  | the specified number in the db named by
  | "dbname". The result will be prefixed with
  | "dbname".
  */
pub fn sst_table_file_name(
        dbname: &String,
        number: u64) -> String {
    
    todo!();
        /*
            assert(number > 0);
      return MakeFileName(dbname, number, "sst");
        */
}

/**
  | Return the name of the descriptor file for the
  | db named by "dbname" and the specified
  | incarnation number.  The result will be
  | prefixed with "dbname".
  */
pub fn descriptor_file_name(
        dbname: &String,
        number: u64) -> String {
    
    todo!();
        /*
            assert(number > 0);
      char buf[100];
      snprintf(buf, sizeof(buf), "/MANIFEST-%06llu",
               static_cast<unsigned long long>(number));
      return dbname + buf;
        */
}

/**
  | Return the name of the current file.
  | This file contains the name of the current
  | manifest file.
  | 
  | The result will be prefixed with "dbname".
  |
  */
pub fn current_file_name(dbname: &String) -> String {
    
    todo!();
        /*
            return dbname + "/CURRENT";
        */
}

/**
  | Return the name of the lock file for the
  | db named by "dbname". The result will
  | be prefixed with "dbname".
  |
  */
pub fn lock_file_name(dbname: &String) -> String {
    
    todo!();
        /*
            return dbname + "/LOCK";
        */
}

/**
  | Return the name of a temporary file owned by
  | the db named "dbname".
  |
  | The result will be prefixed with "dbname".
  */
pub fn temp_file_name(
        dbname: &String,
        number: u64) -> String {
    
    todo!();
        /*
            assert(number > 0);
      return MakeFileName(dbname, number, "dbtmp");
        */
}

/**
  | Return the name of the info log file for
  | "dbname".
  |
  */
pub fn info_log_file_name(dbname: &String) -> String {
    
    todo!();
        /*
            return dbname + "/LOG";
        */
}

/**
  | Return the name of the old info log file
  | for "dbname".
  |
  */
pub fn old_info_log_file_name(dbname: &String) -> String {
    
    todo!();
        /*
            return dbname + "/LOG.old";
        */
}

/**
  | If filename is a leveldb file, store the type
  | of the file in *type.
  |
  | The number encoded in the filename is stored in
  | *number.  If the filename was successfully
  | parsed, returns true.  Else return false.
  |
  ----------------------
  | Owned filenames have the form:
  |    dbname/CURRENT
  |    dbname/LOCK
  |    dbname/LOG
  |    dbname/LOG.old
  |    dbname/MANIFEST-[0-9]+
  |    dbname/[0-9]+.(log|sst|ldb)
  */
pub fn parse_file_name(
        filename: &String,
        number:   *mut u64,
        ty:       *mut FileType) -> bool {
    
    todo!();
        /*
            Slice rest(filename);
      if (rest == "CURRENT") {
        *number = 0;
        *type = kCurrentFile;
      } else if (rest == "LOCK") {
        *number = 0;
        *type = kDBLockFile;
      } else if (rest == "LOG" || rest == "LOG.old") {
        *number = 0;
        *type = kInfoLogFile;
      } else if (rest.starts_with("MANIFEST-")) {
        rest.remove_prefix(strlen("MANIFEST-"));
        uint64_t num;
        if (!ConsumeDecimalNumber(&rest, &num)) {
          return false;
        }
        if (!rest.empty()) {
          return false;
        }
        *type = kDescriptorFile;
        *number = num;
      } else {
        // Avoid strtoull() to keep filename format independent of the
        // current locale
        uint64_t num;
        if (!ConsumeDecimalNumber(&rest, &num)) {
          return false;
        }
        Slice suffix = rest;
        if (suffix == Slice(".log")) {
          *type = kLogFile;
        } else if (suffix == Slice(".sst") || suffix == Slice(".ldb")) {
          *type = kTableFile;
        } else if (suffix == Slice(".dbtmp")) {
          *type = kTempFile;
        } else {
          return false;
        }
        *number = num;
      }
      return true;
        */
}