comparison base/TempWriteFile.cpp @ 1359:1c9bbbb6116a 3.0-integration

Use W64 instead of WAV for decoded files; use Ogg reader in preference to WAV one for Ogg files (WAV reader works, via libsndfile, but doesn't load metadata); fix Ogg reader to use QFile open instead of non-Win32-compatible API; add more encoder tests, audio writer test, midi reader test
author Chris Cannam
date Tue, 10 Jan 2017 10:58:25 +0000
parents e802e550a1f2
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1358:b7be05d57f0a 1359:1c9bbbb6116a
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 cerr << "TempWriteFile: Failed to create temporary file in directory of " << m_target << ": " << temp.errorString() << endl; 30 SVCERR << "TempWriteFile: Failed to create temporary file in directory of " << m_target << ": " << temp.errorString() << 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
52 void 52 void
53 TempWriteFile::moveToTarget() 53 TempWriteFile::moveToTarget()
54 { 54 {
55 if (m_temp == "") return; 55 if (m_temp == "") return;
56 56
57 QDir dir(QFileInfo(m_temp).dir()); 57 QFile tempFile(m_temp);
58 // According to http://doc.trolltech.com/4.4/qdir.html#rename 58 QFile targetFile(m_target);
59 // some systems fail, if renaming over an existing file. 59
60 // Therefore, delete first the existing file. 60 if (targetFile.exists()) {
61 if (dir.exists(m_target)) dir.remove(m_target); 61 if (!targetFile.remove()) {
62 if (!dir.rename(m_temp, m_target)) { 62 SVCERR << "TempWriteFile: WARNING: Failed to remove existing target file " << m_target << " prior to moving temporary file " << m_temp << " to it" << endl;
63 cerr << "TempWriteFile: Failed to rename temporary file " << m_temp << " to target " << m_target << endl; 63 }
64 }
65
66 if (!tempFile.rename(m_target)) {
67 SVCERR << "TempWriteFile: Failed to rename temporary file " << m_temp << " to target " << m_target << endl;
64 throw FileOperationFailed(m_temp, "rename"); 68 throw FileOperationFailed(m_temp, "rename");
65 } 69 }
66 70
67 m_temp = ""; 71 m_temp = "";
68 } 72 }