Changeset 462 for trunk/lib/File.cc


Ignore:
Timestamp:
Aug 21, 2007, 12:34:37 PM (14 years ago)
Author:
Jari Häkkinen
Message:

Merged patch release 0.6.2 to the trunk. Delta 0.6.2 - 0.6.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/File.cc

    r452 r462  
    3535
    3636#include <cassert>
     37#include <cstdio>
    3738#include <ctime>
    3839#include <fstream>
     
    366367    stat(path().c_str(),&nodestat);
    367368   
    368     // finally move printed temporary file to original file
    369     rename(tmpname, path().c_str());
     369    // finally copy temporary file to replace original file, and
     370    // remove the temporary file
     371    try {
     372      copy_file(tmpname, path());
     373    }
     374    catch (std::runtime_error e) {
     375      // catch exception, cleanup, and rethrow
     376      std::cerr << "File::print_copyright: Exception caught, "
     377                << "removing temporary file " << tmpname << std::endl;
     378      if (unlink(tmpname))
     379        throw runtime_error(std::string("File::print_copyright: ") +
     380                            "failed to unlink temporary file" + tmpname);
     381      throw;
     382    }
     383    if (unlink(tmpname))
     384      throw runtime_error(std::string("File::print_copyright: ") +
     385                          "failed to unlink temporary file" + tmpname);
     386
    370387    chmod(path().c_str(), nodestat.st_mode);
    371388  }
Note: See TracChangeset for help on using the changeset viewer.