Mercurial > hg > svcore
comparison transform/FileFeatureWriter.cpp @ 604:4541581067f3
* Better handling of failed-to-open-output-stream situations; ensure CSV
writer closes files when they're finished rather than when it's finished
author | Chris Cannam |
---|---|
date | Tue, 08 Sep 2009 16:52:36 +0000 |
parents | 7065e921f122 |
children | 521438145bd7 |
comparison
equal
deleted
inserted
replaced
603:e43368ec5ff0 | 604:4541581067f3 |
---|---|
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 \"" | |
63 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; | |
62 delete m_files.begin()->second; | 64 delete m_files.begin()->second; |
63 m_files.erase(m_files.begin()); | 65 m_files.erase(m_files.begin()); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
154 QString FileFeatureWriter::getOutputFilename(QString trackId, | 156 QString FileFeatureWriter::getOutputFilename(QString trackId, |
155 TransformId transformId) | 157 TransformId transformId) |
156 { | 158 { |
157 if (m_singleFileName != "") { | 159 if (m_singleFileName != "") { |
158 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { | 160 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { |
159 cerr << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName.toStdString() << "\" exists and neither force nor append flag is specified -- not overwriting" << endl; | 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; |
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; | |
160 return ""; | 163 return ""; |
161 } | 164 } |
162 return m_singleFileName; | 165 return m_singleFileName; |
163 } | 166 } |
164 | 167 |
176 basename = QFileInfo(infilename).baseName(); | 179 basename = QFileInfo(infilename).baseName(); |
177 if (scheme.length() == 1) { | 180 if (scheme.length() == 1) { |
178 infilename = scheme + ":" + infilename; // DOS drive! | 181 infilename = scheme + ":" + infilename; // DOS drive! |
179 } | 182 } |
180 | 183 |
181 // cerr << "trackId = " << trackId.toStdString() << ", url = " << url.toString().toStdString() << ", infilename = " | 184 cerr << "trackId = " << trackId.toStdString() << ", url = " << url.toString().toStdString() << ", infilename = " |
182 // << infilename.toStdString() << ", basename = " << basename.toStdString() << endl; | 185 << infilename.toStdString() << ", basename = " << basename.toStdString() << ", m_baseDir = " << m_baseDir.toStdString() << endl; |
183 | |
184 | 186 |
185 if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath(); | 187 if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath(); |
186 else if (local) dirname = QFileInfo(infilename).absolutePath(); | 188 else if (local) dirname = QFileInfo(infilename).absolutePath(); |
187 else dirname = QDir::currentPath(); | 189 else dirname = QDir::currentPath(); |
190 | |
191 cerr << "dirname = " << dirname.toStdString() << endl; | |
188 | 192 |
189 QString filename; | 193 QString filename; |
190 | 194 |
191 if (m_manyFiles && transformId != "") { | 195 if (m_manyFiles && transformId != "") { |
192 filename = QString("%1_%2.%3").arg(basename).arg(transformId).arg(m_extension); | 196 filename = QString("%1_%2.%3").arg(basename).arg(transformId).arg(m_extension); |
197 filename.replace(':', '_'); // ':' not permitted in Windows | 201 filename.replace(':', '_'); // ':' not permitted in Windows |
198 | 202 |
199 filename = QDir(dirname).filePath(filename); | 203 filename = QDir(dirname).filePath(filename); |
200 | 204 |
201 if (QFileInfo(filename).exists() && !(m_force || m_append)) { | 205 if (QFileInfo(filename).exists() && !(m_force || m_append)) { |
202 cerr << "FileFeatureWriter: ERROR: Output file \"" << filename.toStdString() << "\" exists (for input file or URL \"" << trackId.toStdString() << "\" and transform \"" << transformId.toStdString() << "\") and neither force nor append is specified -- not overwriting" << endl; | 206 cerr << endl << "FileFeatureWriter: ERROR: Output file \"" << filename.toStdString() << "\" exists (for input file or URL \"" << trackId.toStdString() << "\" and transform \"" << transformId.toStdString() << "\") and neither --" << getWriterTag().toStdString() << "-force nor --" << getWriterTag().toStdString() << "-append is specified -- not overwriting" << endl; |
207 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; | |
203 return ""; | 208 return ""; |
204 } | 209 } |
205 | 210 |
206 return filename; | 211 return filename; |
207 } | 212 } |
302 m_streams.begin()->second->flush(); | 307 m_streams.begin()->second->flush(); |
303 delete m_streams.begin()->second; | 308 delete m_streams.begin()->second; |
304 m_streams.erase(m_streams.begin()); | 309 m_streams.erase(m_streams.begin()); |
305 } | 310 } |
306 while (!m_files.empty()) { | 311 while (!m_files.empty()) { |
312 cerr << "FileFeatureWriter::finish: NOTE: Closing feature file \"" | |
313 << m_files.begin()->second->fileName().toStdString() << "\"" << endl; | |
307 delete m_files.begin()->second; | 314 delete m_files.begin()->second; |
308 m_files.erase(m_files.begin()); | 315 m_files.erase(m_files.begin()); |
309 } | 316 } |
310 m_prevstream = 0; | 317 m_prevstream = 0; |
311 } | 318 } |