Skip to content

Commit

Permalink
Fixing an issue where a carriage return in the CURRENT file would con…
Browse files Browse the repository at this point in the history
…sider our files as corrupted. (#8)

Co-authored-by: Alex Troyer <[email protected]>
  • Loading branch information
yabmek-msft and AlexTroyer authored Dec 20, 2024
1 parent a995da2 commit a985fcc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,17 @@ Status VersionSet::Recover(bool* save_manifest) {
if (!s.ok()) {
return s;
}
if (current.empty() || current[current.size() - 1] != '\n') {
const size_t size = current.size();
if (size == 0 || (current[size - 1] != '\n' && current[size - 1] != '\r')) {
return Status::Corruption("CURRENT file does not end with newline");
}
current.resize(current.size() - 1);

int resizeSize = 1;
if (size >= 2 && current[size - 2] == '\r') {
resizeSize = 2;
}

current.resize(size - resizeSize);

std::string dscname = dbname_ + "/" + current;
SequentialFile* file;
Expand Down

0 comments on commit a985fcc

Please sign in to comment.