Changeset 456
- Timestamp:
- Aug 21, 2007, 9:56:06 AM (16 years ago)
- Location:
- branches/0.6-stable/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.6-stable/lib/File.cc
r430 r456 34 34 35 35 #include <cassert> 36 #include <cstdio> 36 37 #include <ctime> 37 38 #include <fstream> … … 254 255 tmp.close(); 255 256 close(fd); 256 // finally move printed temporary file to original file 257 rename(tmpname, path().c_str()); 257 // finally copy temporary file to replace original file, and 258 // remove the temporary file 259 try { 260 copy_file(tmpname, path()); 261 } 262 catch (std::runtime_error e) { 263 // catch exception, cleanup, and rethrow 264 std::cerr << "File::print_copyright: Exception caught, " 265 << "removing temporary file " << tmpname << std::endl; 266 if (unlink(tmpname)) 267 throw runtime_error(std::string("File::print_copyright: ") + 268 "failed to unlink temporary file" + tmpname); 269 throw; 270 } 271 if (unlink(tmpname)) 272 throw runtime_error(std::string("File::print_copyright: ") + 273 "failed to unlink temporary file" + tmpname); 258 274 } 259 275 -
branches/0.6-stable/lib/File.h
r430 r456 66 66 const Stats& parse(const bool verbose=false); 67 67 68 /** 69 @throw std::runtime_error when a file error is encountered 70 updating the copyrights. 71 */ 68 72 void print_copyright(std::map<std::string, Alias>&) const; 69 73 -
branches/0.6-stable/lib/utility.cc
r430 r456 61 61 62 62 63 void copy_file(const std::string& source, const std::string& target) 64 { 65 std::ofstream o(target.c_str()); 66 std::ifstream i(source.c_str()); 67 while (i.good()) { 68 char ch=i.get(); 69 if (i.good()) 70 o.put(ch); 71 if (!o.good()) 72 throw std::runtime_error(std::string("copy_file: ") + 73 "writing target file failed '" + target + "'"); 74 } 75 if (!i.eof() && (i.bad() || i.fail())) // fail on everything except eof 76 throw std::runtime_error(std::string("copy_file: ") + 77 "error reading source file '" + source + "'"); 78 i.close(); o.close(); 79 } 80 81 63 82 std::string file_name(const std::string& full_path) 64 83 { -
branches/0.6-stable/lib/utility.h
r430 r456 53 53 /// 54 54 int access_rights(const std::string& path,const std::string& bits); 55 56 /** 57 @brief Copy file \a source to \a target. 58 59 @throw std::runtime_error when read error of \a source or write 60 error for \a target is encountered. 61 */ 62 void copy_file(const std::string& source, const std::string& target); 55 63 56 64 ///
Note: See TracChangeset
for help on using the changeset viewer.