Changeset 1132
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/File.cc
r1097 r1132 401 401 size_t start_at_line, size_t end_at_line) const 402 402 { 403 // Code copied from Gnuplot -r70 404 char tmpname[]="/tmp/svndigestXXXXXX"; 405 int fd=mkstemp(tmpname); // mkstemp return a file descriptor 406 if (fd == -1) 407 throw std::runtime_error(std::string("Failed to get unique filename: ") + 408 tmpname); 409 // Jari would like to do something like 'std::ofstream tmp(fd);' 410 // but has to settle for (which is stupid since the file is 411 // already open for writing. 412 std::ofstream tmp(tmpname); 403 // embrace filename with brackets #filename# 404 std::string tmpname = concatenate_path(directory_name(path()), 405 "#" + file_name(path()) + "#"); 406 std::ofstream tmp(tmpname.c_str()); 413 407 414 408 using namespace std; … … 438 432 is.close(); 439 433 tmp.close(); 440 close(fd);441 // get file permission442 struct stat nodestat;443 stat(path().c_str(),&nodestat);444 434 445 // finally copy temporary file to replace original file, and 446 // remove the temporary file 447 try { 448 copy_file(tmpname, path()); 449 } 450 catch (std::runtime_error e) { 451 // catch exception, cleanup, and rethrow 452 std::cerr << "svncopyright: File::print_copyright: Exception caught, " 453 << "removing temporary file " << tmpname << std::endl; 454 if (unlink(tmpname)) 455 throw runtime_error(std::string("File::print_copyright: ") + 456 "failed to unlink temporary file" + tmpname); 457 throw; 458 } 459 if (unlink(tmpname)) 460 throw runtime_error(std::string("File::print_copyright: ") + 461 "failed to unlink temporary file" + tmpname); 462 463 chmod(path().c_str(), nodestat.st_mode); 435 // finally rename file 436 rename(tmpname, path()); 464 437 } 465 438 -
trunk/lib/utility.cc
r1101 r1132 289 289 290 290 291 void rename(const std::string& from, const std::string to) 292 { 293 int code = ::rename(from.c_str(), to.c_str()); 294 if (code){ 295 std::stringstream ss; 296 ss << "rename(" << from << ", " << to << "): failed\n" << strerror(errno); 297 throw std::runtime_error(ss.str()); 298 } 299 } 300 301 291 302 void replace(std::string& str, std::string old_str, std::string new_str) 292 303 { -
trunk/lib/utility.h
r1098 r1132 176 176 bool regexp(const std::string& pattern, const std::string& str, 177 177 std::vector<std::string>& vec); 178 179 /** 180 same as rename(2) but throw errno if error is encountered 181 182 \see man rename 183 */ 184 void rename(const std::string& from, const std::string to); 178 185 179 186 /**
Note: See TracChangeset
for help on using the changeset viewer.