ISIS Core Library 0.7.2 (api 3.0.0)
|
00001 /* 00002 <one line to give the program's name and a brief idea of what it does.> 00003 Copyright (C) <year> <name of author> 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 00018 */ 00019 00020 #ifdef _MSC_VER 00021 #pragma warning(disable:4996) 00022 #endif 00023 00024 #include <stdio.h> 00025 #include <fstream> 00026 #define BOOST_FILESYSTEM_VERSION 2 //@todo switch to 3 as soon as we drop support for boost < 1.44 00027 #include <boost/filesystem/operations.hpp> 00028 #include "tmpfile.hpp" 00029 #include "message.hpp" 00030 #include "common.hpp" 00031 00032 namespace isis 00033 { 00034 namespace util 00035 { 00036 00037 TmpFile::TmpFile( std::string prefix, std::string sufix ) 00038 { 00039 // @todo critical block - should be locked 00040 boost::filesystem::path dummy( tmpnam( NULL ) ); 00041 boost::filesystem::path::operator=( dummy.branch_path() / boost::filesystem::path( prefix + dummy.leaf() + sufix ) ); 00042 LOG( Debug, info ) << "Creating temporary file " << file_string(); 00043 std::ofstream( file_string().c_str() ).exceptions( std::ios::failbit | std::ios::badbit ); 00044 } 00045 00046 TmpFile::~TmpFile() 00047 { 00048 if ( boost::filesystem::exists( *this ) ) { 00049 boost::filesystem::remove( *this ); 00050 LOG( Debug, verbose_info ) << "Removing temporary " << file_string(); 00051 } else { 00052 LOG( Debug, warning ) << "Temporary file " << file_string() << " does not exist, won't delete it"; 00053 } 00054 } 00055 } 00056 }