Skip to content

Commit

Permalink
Fix deletion of orphan nodestore directories:
Browse files Browse the repository at this point in the history
Orphaned nodestore directories should only be deleted
if the proper nodestore directories are confirmed to
exist.
  • Loading branch information
mtrippled authored and nbougalis committed Mar 1, 2022
1 parent c2a08a1 commit 06e87e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ripple/app/misc/SHAMapStoreImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ SHAMapStoreImp::dbPaths()
bool writableDbExists = false;
bool archiveDbExists = false;

std::vector<boost::filesystem::path> pathsToDelete;
for (boost::filesystem::directory_iterator it(dbPath);
it != boost::filesystem::directory_iterator();
++it)
Expand All @@ -494,7 +495,7 @@ SHAMapStoreImp::dbPaths()
else if (!state.archiveDb.compare(it->path().string()))
archiveDbExists = true;
else if (!dbPrefix_.compare(it->path().stem().string()))
boost::filesystem::remove_all(it->path());
pathsToDelete.push_back(it->path());
}

if ((!writableDbExists && state.writableDb.size()) ||
Expand Down Expand Up @@ -524,6 +525,10 @@ SHAMapStoreImp::dbPaths()

Throw<std::runtime_error>("state db error");
}

// The necessary directories exist. Now, remove any others.
for (boost::filesystem::path& p : pathsToDelete)
boost::filesystem::remove_all(p);
}

std::unique_ptr<NodeStore::Backend>
Expand Down

0 comments on commit 06e87e0

Please sign in to comment.