Ignore:
Timestamp:
Aug 21, 2007, 9:56:06 AM (14 years ago)
Author:
Jari Häkkinen
Message:

Refs #251.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.6-stable/lib/File.cc

    r430 r456  
    3434
    3535#include <cassert>
     36#include <cstdio>
    3637#include <ctime>
    3738#include <fstream>
     
    254255    tmp.close();
    255256    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);
    258274  }
    259275
Note: See TracChangeset for help on using the changeset viewer.