Mercurial > hg > svcore
comparison transform/FileFeatureWriter.cpp @ 625:608b4dc5ff34
* Improve behaviour when output file write fails (i.e. fail earlier)
author | Chris Cannam |
---|---|
date | Fri, 21 May 2010 10:21:18 +0000 |
parents | 521438145bd7 |
children | 686fc1703a33 |
comparison
equal
deleted
inserted
replaced
624:076dcd2ce209 | 625:608b4dc5ff34 |
---|---|
57 m_streams.begin()->second->flush(); | 57 m_streams.begin()->second->flush(); |
58 delete m_streams.begin()->second; | 58 delete m_streams.begin()->second; |
59 m_streams.erase(m_streams.begin()); | 59 m_streams.erase(m_streams.begin()); |
60 } | 60 } |
61 while (!m_files.empty()) { | 61 while (!m_files.empty()) { |
62 cerr << "FileFeatureWriter::~FileFeatureWriter: NOTE: Closing feature file \"" | 62 if (m_files.begin()->second) { |
63 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; | 63 cerr << "FileFeatureWriter::~FileFeatureWriter: NOTE: Closing feature file \"" |
64 delete m_files.begin()->second; | 64 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; |
65 delete m_files.begin()->second; | |
66 } | |
65 m_files.erase(m_files.begin()); | 67 m_files.erase(m_files.begin()); |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 FileFeatureWriter::ParameterList | 71 FileFeatureWriter::ParameterList |
151 m_force = true; | 153 m_force = true; |
152 } | 154 } |
153 } | 155 } |
154 } | 156 } |
155 | 157 |
156 QString FileFeatureWriter::getOutputFilename(QString trackId, | 158 QString |
157 TransformId transformId) | 159 FileFeatureWriter::getOutputFilename(QString trackId, |
160 TransformId transformId) | |
158 { | 161 { |
159 if (m_singleFileName != "") { | 162 if (m_singleFileName != "") { |
160 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { | 163 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { |
161 cerr << endl << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName.toStdString() << "\" exists and neither --" << getWriterTag().toStdString() << "-force nor --" << getWriterTag().toStdString() << "-append flag is specified -- not overwriting" << endl; | 164 cerr << endl << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName.toStdString() << "\" exists and neither --" << getWriterTag().toStdString() << "-force nor --" << getWriterTag().toStdString() << "-append flag is specified -- not overwriting" << endl; |
162 cerr << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag().toStdString() << "-force" << endl << "and --" << getWriterTag().toStdString() << "-append options" << endl; | 165 cerr << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag().toStdString() << "-force" << endl << "and --" << getWriterTag().toStdString() << "-append options" << endl; |
179 basename = QFileInfo(infilename).completeBaseName(); | 182 basename = QFileInfo(infilename).completeBaseName(); |
180 if (scheme.length() == 1) { | 183 if (scheme.length() == 1) { |
181 infilename = scheme + ":" + infilename; // DOS drive! | 184 infilename = scheme + ":" + infilename; // DOS drive! |
182 } | 185 } |
183 | 186 |
184 cerr << "trackId = " << trackId.toStdString() << ", url = " << url.toString().toStdString() << ", infilename = " | 187 // cerr << "trackId = " << trackId.toStdString() << ", url = " << url.toString().toStdString() << ", infilename = " |
185 << infilename.toStdString() << ", basename = " << basename.toStdString() << ", m_baseDir = " << m_baseDir.toStdString() << endl; | 188 // << infilename.toStdString() << ", basename = " << basename.toStdString() << ", m_baseDir = " << m_baseDir.toStdString() << endl; |
186 | 189 |
187 if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath(); | 190 if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath(); |
188 else if (local) dirname = QFileInfo(infilename).absolutePath(); | 191 else if (local) dirname = QFileInfo(infilename).absolutePath(); |
189 else dirname = QDir::currentPath(); | 192 else dirname = QDir::currentPath(); |
190 | 193 |
191 cerr << "dirname = " << dirname.toStdString() << endl; | 194 // cerr << "dirname = " << dirname.toStdString() << endl; |
192 | 195 |
193 QString filename; | 196 QString filename; |
194 | 197 |
195 if (m_manyFiles && transformId != "") { | 198 if (m_manyFiles && transformId != "") { |
196 filename = QString("%1_%2.%3").arg(basename).arg(transformId).arg(m_extension); | 199 filename = QString("%1_%2.%3").arg(basename).arg(transformId).arg(m_extension); |
209 } | 212 } |
210 | 213 |
211 return filename; | 214 return filename; |
212 } | 215 } |
213 | 216 |
214 | 217 void |
215 QFile *FileFeatureWriter::getOutputFile(QString trackId, | 218 FileFeatureWriter::testOutputFile(QString trackId, |
216 TransformId transformId) | 219 TransformId transformId) |
220 { | |
221 if (m_stdout) return; | |
222 QString filename = getOutputFilename(trackId, transformId); | |
223 if (filename == "") { | |
224 throw FailedToOpenOutputStream(trackId, transformId); | |
225 } | |
226 } | |
227 | |
228 QFile * | |
229 FileFeatureWriter::getOutputFile(QString trackId, | |
230 TransformId transformId) | |
217 { | 231 { |
218 pair<QString, TransformId> key; | 232 pair<QString, TransformId> key; |
219 | 233 |
220 if (m_singleFileName != "") { | 234 if (m_singleFileName != "") { |
221 key = pair<QString, TransformId>("", ""); | 235 key = pair<QString, TransformId>("", ""); |
227 | 241 |
228 if (m_files.find(key) == m_files.end()) { | 242 if (m_files.find(key) == m_files.end()) { |
229 | 243 |
230 QString filename = getOutputFilename(trackId, transformId); | 244 QString filename = getOutputFilename(trackId, transformId); |
231 | 245 |
232 if (filename == "") { // stdout | 246 if (filename == "") { // stdout or failure |
233 return 0; | 247 return 0; |
234 } | 248 } |
235 | 249 |
236 cerr << "FileFeatureWriter: NOTE: Using output filename \"" | 250 cerr << "FileFeatureWriter: NOTE: Using output filename \"" |
237 << filename.toStdString() << "\"" << endl; | 251 << filename.toStdString() << "\"" << endl; |
307 m_streams.begin()->second->flush(); | 321 m_streams.begin()->second->flush(); |
308 delete m_streams.begin()->second; | 322 delete m_streams.begin()->second; |
309 m_streams.erase(m_streams.begin()); | 323 m_streams.erase(m_streams.begin()); |
310 } | 324 } |
311 while (!m_files.empty()) { | 325 while (!m_files.empty()) { |
312 cerr << "FileFeatureWriter::finish: NOTE: Closing feature file \"" | 326 if (m_files.begin()->second) { |
313 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; | 327 cerr << "FileFeatureWriter::finish: NOTE: Closing feature file \"" |
314 delete m_files.begin()->second; | 328 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; |
329 delete m_files.begin()->second; | |
330 } | |
315 m_files.erase(m_files.begin()); | 331 m_files.erase(m_files.begin()); |
316 } | 332 } |
317 m_prevstream = 0; | 333 m_prevstream = 0; |
318 } | 334 } |
319 | 335 |