From 646f3c195ffc1ea0960948d7d1a22bb3a2a9c4b7 Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Mon, 16 May 2011 17:11:50 +0200
Subject: [PATCH] ENH: test file existence before asking GDALImageIO to read it

---
 Code/IO/otbTileMapImageIO.cxx | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Code/IO/otbTileMapImageIO.cxx b/Code/IO/otbTileMapImageIO.cxx
index e36633098c..2be3197692 100644
--- a/Code/IO/otbTileMapImageIO.cxx
+++ b/Code/IO/otbTileMapImageIO.cxx
@@ -221,6 +221,13 @@ void TileMapImageIO::GenerateTileInfo(double x, double y, int numTileX, int numT
  */
 bool TileMapImageIO::CanReadFromCache(std::string filename)
 {
+  // Verify that the file exists and is not a directory
+  bool fileExists = itksys::SystemTools::FileExists(filename.c_str(), true);
+  if (!fileExists)
+    {
+    return false;
+    }
+
   itk::ImageIOBase::Pointer imageIO;
   imageIO = otb::GDALImageIO::New();
   return imageIO->CanReadFile(filename.c_str());
-- 
GitLab