comparison transform/FileFeatureWriter.cpp @ 626:686fc1703a33

* Avoid failing on second and subsequent input files in single-output-file mode (because first input file caused output file to be open, so second input file failed because output "already existed")
author Chris Cannam
date Mon, 24 May 2010 16:04:10 +0000
parents 608b4dc5ff34
children cd1fa6387cb9
comparison
equal deleted inserted replaced
625:608b4dc5ff34 626:686fc1703a33
216 216
217 void 217 void
218 FileFeatureWriter::testOutputFile(QString trackId, 218 FileFeatureWriter::testOutputFile(QString trackId,
219 TransformId transformId) 219 TransformId transformId)
220 { 220 {
221 if (m_stdout) return; 221 // Obviously, if we're writing to stdout we can't test for an
222 // openable output file. But when writing a single file we don't
223 // want to either, because this test would fail on the second and
224 // subsequent input files (because the file would already exist).
225 // getOutputFile does the right thing in this case, so we just
226 // leave it to it
227 if (m_stdout || m_singleFileName != "") return;
228
222 QString filename = getOutputFilename(trackId, transformId); 229 QString filename = getOutputFilename(trackId, transformId);
223 if (filename == "") { 230 if (filename == "") {
224 throw FailedToOpenOutputStream(trackId, transformId); 231 throw FailedToOpenOutputStream(trackId, transformId);
225 } 232 }
226 } 233 }
264 << "\" for writing" << endl; 271 << "\" for writing" << endl;
265 delete file; 272 delete file;
266 m_files[key] = 0; 273 m_files[key] = 0;
267 throw FailedToOpenFile(filename); 274 throw FailedToOpenFile(filename);
268 } 275 }
269 276
270 m_files[key] = file; 277 m_files[key] = file;
271 } 278 }
272 279
273 return m_files[key]; 280 return m_files[key];
274 } 281 }
279 { 286 {
280 QFile *file = getOutputFile(trackId, transformId); 287 QFile *file = getOutputFile(trackId, transformId);
281 if (!file && !m_stdout) { 288 if (!file && !m_stdout) {
282 return 0; 289 return 0;
283 } 290 }
284 291
285 if (m_streams.find(file) == m_streams.end()) { 292 if (m_streams.find(file) == m_streams.end()) {
286 if (m_stdout) { 293 if (m_stdout) {
287 m_streams[file] = new QTextStream(stdout); 294 m_streams[file] = new QTextStream(stdout);
288 } else { 295 } else {
289 m_streams[file] = new QTextStream(file); 296 m_streams[file] = new QTextStream(file);