From f763bca42ebe9fe5d6a15001f82ce8ff4bbd1f56 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 9 Aug 2012 15:17:24 +0100 Subject: [PATCH] BUG: #include of empty filename creates confusing error message (Mark Olesen) When using #include or #includeIfPresent, it is easy to generate an empty file name. For example, #include "~OpenFOAM/missing-path/file" On error, findEtcFile() returns an empty fileName. This was treated as a relative name, which meant there was an attempt to open the parent directory as a file. The resulting error message was confusing: --> FOAM FATAL IO ERROR: Attempt to put back onto bad stream file: /CASE/PATH/system at line 1. From function void Istream::putBack(const token&) in file db/IOstreams/IOstreams/Istream.C at line 34. - fix by leaving empty expansions as-is --- .../functionEntries/includeEntry/includeEntry.C | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index 60478f9609..eb8fd09280 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,13 +74,15 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName fileName fName(is); fName.expand(); - // relative name - if (!fName.isAbsolute()) + if (fName.empty() || fName.isAbsolute()) { - fName = fileName(is.name()).path()/fName; + return fName; + } + else + { + // relative name + return fileName(is.name()).path()/fName; } - - return fName; }