comparison base/TempWriteFile.cpp @ 689:573d45e9487b

Merge from debug-output branch
author Chris Cannam
date Tue, 14 Jun 2011 14:47:59 +0100
parents b4a8d8221eaf
children e802e550a1f2
comparison
equal deleted inserted replaced
688:be43b2fe68e8 689:573d45e9487b
25 { 25 {
26 QTemporaryFile temp(m_target + "."); 26 QTemporaryFile temp(m_target + ".");
27 temp.setAutoRemove(false); 27 temp.setAutoRemove(false);
28 temp.open(); // creates the file and opens it atomically 28 temp.open(); // creates the file and opens it atomically
29 if (temp.error()) { 29 if (temp.error()) {
30 std::cerr << "TempWriteFile: Failed to create temporary file in directory of " << m_target.toStdString() << ": " << temp.errorString().toStdString() << std::endl; 30 std::cerr << "TempWriteFile: Failed to create temporary file in directory of " << m_target << ": " << temp.errorString() << std::endl;
31 throw FileOperationFailed(temp.fileName(), "creation"); 31 throw FileOperationFailed(temp.fileName(), "creation");
32 } 32 }
33 33
34 m_temp = temp.fileName(); 34 m_temp = temp.fileName();
35 temp.close(); // does not remove the file 35 temp.close(); // does not remove the file
58 // According to http://doc.trolltech.com/4.4/qdir.html#rename 58 // According to http://doc.trolltech.com/4.4/qdir.html#rename
59 // some systems fail, if renaming over an existing file. 59 // some systems fail, if renaming over an existing file.
60 // Therefore, delete first the existing file. 60 // Therefore, delete first the existing file.
61 if (dir.exists(m_target)) dir.remove(m_target); 61 if (dir.exists(m_target)) dir.remove(m_target);
62 if (!dir.rename(m_temp, m_target)) { 62 if (!dir.rename(m_temp, m_target)) {
63 std::cerr << "TempWriteFile: Failed to rename temporary file " << m_temp.toStdString() << " to target " << m_target.toStdString() << std::endl; 63 std::cerr << "TempWriteFile: Failed to rename temporary file " << m_temp << " to target " << m_target << std::endl;
64 throw FileOperationFailed(m_temp, "rename"); 64 throw FileOperationFailed(m_temp, "rename");
65 } 65 }
66 66
67 m_temp = ""; 67 m_temp = "";
68 } 68 }