From f4e0bf05f5fa40b7e726c0105115439f6d54c56a Mon Sep 17 00:00:00 2001
From: Florent Rougon <f.rougon@free.fr>
Date: Thu, 20 Oct 2016 16:55:36 +0200
Subject: [PATCH] Make sure we open exactly the desired file when loading
 apt.dat files

Without this change, it would be possible that the NavCache is rebuilt
using $FG_ROOT/Airports/apt.dat (if $FG_ROOT/Airports/apt.dat.gz is
manually deleted) despite APTLoader::readAptDatFile() using
sg_gzifstream() with $FG_ROOT/Airports/apt.dat.gz, but the NavCache
would still contain a reference to $FG_ROOT/Airports/apt.dat.gz and log
messages would pretend we are reading this (non-existent) file.

Unrelated: the change

-          "Loaded data for " << nbAirports << " airports" );
+          "Loaded data for " << nbLoadedAirports << " airports" );

has no incidence given the current code, but it is more logical and
future-proof (in case someone adds a continue statement inside the for
loop starting at line 224...).
---
 src/Airports/apt_loader.cxx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Airports/apt_loader.cxx b/src/Airports/apt_loader.cxx
index 90da964bb..0da074dee 100644
--- a/src/Airports/apt_loader.cxx
+++ b/src/Airports/apt_loader.cxx
@@ -89,7 +89,7 @@ void APTLoader::readAptDatFile(const SGPath &aptdb_file,
                                std::size_t totalSizeOfAllAptDatFiles)
 {
   string apt_dat = aptdb_file.utf8Str(); // full path to the file being parsed
-  sg_gzifstream in(aptdb_file);
+  sg_gzifstream in(aptdb_file, std::ios_base::in | std::ios_base::binary, true);
 
   if ( !in.is_open() ) {
     const std::string errMsg = simgear::strutils::error_string(errno);
@@ -304,7 +304,7 @@ void APTLoader::loadAirports()
   } // of loop over 'airportInfoMap'
 
   SG_LOG( SG_GENERAL, SG_INFO,
-          "Loaded data for " << nbAirports << " airports" );
+          "Loaded data for " << nbLoadedAirports << " airports" );
 }
 
 // Tell whether an apt.dat line is blank or a comment line