Skip to content

Commit a6aac80

Browse files
authored
fix(tools): flush when draw to file, stop when cin is invalid (#425)
Signed-off-by: Alex Chi <[email protected]>
1 parent 7fc641f commit a6aac80

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/storage/index/b_plus_tree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void BPLUSTREE_TYPE::Draw(BufferPoolManager *bpm, const std::string &outf) {
166166
out << "digraph G {" << std::endl;
167167
ToGraph(reinterpret_cast<BPlusTreePage *>(bpm->FetchPage(root_page_id_)->GetData()), bpm, out);
168168
out << "}" << std::endl;
169+
out.flush();
169170
out.close();
170171
}
171172

tools/b_plus_tree_printer/b_plus_tree_printer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ using bustub::DiskManager;
2525
using bustub::Exception;
2626
using bustub::GenericComparator;
2727
using bustub::GenericKey;
28-
using bustub::RID;
29-
using bustub::Transaction;
3028
using bustub::page_id_t;
3129
using bustub::ParseCreateStatement;
30+
using bustub::RID;
31+
using bustub::Transaction;
3232

3333
auto UsageMessage() -> std::string {
3434
std::string message =
@@ -84,6 +84,9 @@ auto main(int argc, char **argv) -> int {
8484
while (!quit) {
8585
std::cout << "> ";
8686
std::cin >> instruction;
87+
if (!std::cin) {
88+
break;
89+
}
8790
switch (instruction) {
8891
case 'c':
8992
std::cin >> filename;

0 commit comments

Comments
 (0)