Skip to content

Commit

Permalink
Open .committed files read-only (#6671)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyashton authored Nov 28, 2024
1 parent 7991921 commit 04a550f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/host/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,20 @@ namespace asynchost
from_existing_file(from_existing_file_)
{
auto file_path = (fs::path(dir) / fs::path(file_name));
file = fopen(file_path.c_str(), "r+b");

committed = is_ledger_file_name_committed(file_name);
start_idx = get_start_idx_from_file_name(file_name);

const auto mode = committed ? "rb" : "r+b";

file = fopen(file_path.c_str(), mode);

if (!file)
{
throw std::logic_error(fmt::format(
"Unable to open ledger file {}: {}", file_path, strerror(errno)));
}

committed = is_ledger_file_name_committed(file_name);
start_idx = get_start_idx_from_file_name(file_name);

// First, get full size of file
fseeko(file, 0, SEEK_END);
size_t total_file_size = ftello(file);
Expand Down

0 comments on commit 04a550f

Please sign in to comment.