Mercurial > hg > svcore
comparison data/fileio/FileSource.cpp @ 529:993e0a4f1343
* Try to avoid leaving output files open after completion
author | Chris Cannam |
---|---|
date | Tue, 20 Jan 2009 18:10:31 +0000 |
parents | 57857a57a03a |
children | d7f3dfe6f9a4 |
comparison
equal
deleted
inserted
replaced
528:57857a57a03a | 529:993e0a4f1343 |
---|---|
44 FileSource::RemoteLocalMap | 44 FileSource::RemoteLocalMap |
45 FileSource::m_remoteLocalMap; | 45 FileSource::m_remoteLocalMap; |
46 | 46 |
47 QMutex | 47 QMutex |
48 FileSource::m_mapMutex; | 48 FileSource::m_mapMutex; |
49 | |
50 #ifdef DEBUG_FILE_SOURCE | |
51 static int extantCount = 0; | |
52 static std::map<QString, int> urlExtantCountMap; | |
53 static void incCount(QString url) { | |
54 ++extantCount; | |
55 if (urlExtantCountMap.find(url) == urlExtantCountMap.end()) { | |
56 urlExtantCountMap[url] = 1; | |
57 } else { | |
58 ++urlExtantCountMap[url]; | |
59 } | |
60 std::cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << std::endl; | |
61 } | |
62 static void decCount(QString url) { | |
63 --extantCount; | |
64 --urlExtantCountMap[url]; | |
65 std::cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << std::endl; | |
66 } | |
67 #endif | |
49 | 68 |
50 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, | 69 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, |
51 QString preferredContentType) : | 70 QString preferredContentType) : |
52 m_url(fileOrUrl), | 71 m_url(fileOrUrl), |
53 m_ftp(0), | 72 m_ftp(0), |
62 m_reporter(reporter), | 81 m_reporter(reporter), |
63 m_refCounted(false) | 82 m_refCounted(false) |
64 { | 83 { |
65 #ifdef DEBUG_FILE_SOURCE | 84 #ifdef DEBUG_FILE_SOURCE |
66 std::cerr << "FileSource::FileSource(" << fileOrUrl.toStdString() << ")" << std::endl; | 85 std::cerr << "FileSource::FileSource(" << fileOrUrl.toStdString() << ")" << std::endl; |
86 incCount(m_url.toString()); | |
67 #endif | 87 #endif |
68 | 88 |
69 if (!canHandleScheme(m_url)) { | 89 if (!canHandleScheme(m_url)) { |
70 std::cerr << "FileSource::FileSource: ERROR: Unsupported scheme in URL \"" << m_url.toString().toStdString() << "\"" << std::endl; | 90 std::cerr << "FileSource::FileSource: ERROR: Unsupported scheme in URL \"" << m_url.toString().toStdString() << "\"" << std::endl; |
71 m_errorString = tr("Unsupported scheme in URL"); | 91 m_errorString = tr("Unsupported scheme in URL"); |
130 m_reporter(reporter), | 150 m_reporter(reporter), |
131 m_refCounted(false) | 151 m_refCounted(false) |
132 { | 152 { |
133 #ifdef DEBUG_FILE_SOURCE | 153 #ifdef DEBUG_FILE_SOURCE |
134 std::cerr << "FileSource::FileSource(" << url.toString().toStdString() << ") [as url]" << std::endl; | 154 std::cerr << "FileSource::FileSource(" << url.toString().toStdString() << ") [as url]" << std::endl; |
155 incCount(m_url.toString()); | |
135 #endif | 156 #endif |
136 | 157 |
137 if (!canHandleScheme(m_url)) { | 158 if (!canHandleScheme(m_url)) { |
138 std::cerr << "FileSource::FileSource: ERROR: Unsupported scheme in URL \"" << m_url.toString().toStdString() << "\"" << std::endl; | 159 std::cerr << "FileSource::FileSource: ERROR: Unsupported scheme in URL \"" << m_url.toString().toStdString() << "\"" << std::endl; |
139 m_errorString = tr("Unsupported scheme in URL"); | 160 m_errorString = tr("Unsupported scheme in URL"); |
161 m_reporter(rf.m_reporter), | 182 m_reporter(rf.m_reporter), |
162 m_refCounted(false) | 183 m_refCounted(false) |
163 { | 184 { |
164 #ifdef DEBUG_FILE_SOURCE | 185 #ifdef DEBUG_FILE_SOURCE |
165 std::cerr << "FileSource::FileSource(" << m_url.toString().toStdString() << ") [copy ctor]" << std::endl; | 186 std::cerr << "FileSource::FileSource(" << m_url.toString().toStdString() << ") [copy ctor]" << std::endl; |
187 incCount(m_url.toString()); | |
166 #endif | 188 #endif |
167 | 189 |
168 if (!canHandleScheme(m_url)) { | 190 if (!canHandleScheme(m_url)) { |
169 std::cerr << "FileSource::FileSource: ERROR: Unsupported scheme in URL \"" << m_url.toString().toStdString() << "\"" << std::endl; | 191 std::cerr << "FileSource::FileSource: ERROR: Unsupported scheme in URL \"" << m_url.toString().toStdString() << "\"" << std::endl; |
170 m_errorString = tr("Unsupported scheme in URL"); | 192 m_errorString = tr("Unsupported scheme in URL"); |
205 | 227 |
206 FileSource::~FileSource() | 228 FileSource::~FileSource() |
207 { | 229 { |
208 #ifdef DEBUG_FILE_SOURCE | 230 #ifdef DEBUG_FILE_SOURCE |
209 std::cerr << "FileSource(" << m_url.toString().toStdString() << ")::~FileSource" << std::endl; | 231 std::cerr << "FileSource(" << m_url.toString().toStdString() << ")::~FileSource" << std::endl; |
232 decCount(m_url.toString()); | |
210 #endif | 233 #endif |
211 | 234 |
212 cleanup(); | 235 cleanup(); |
213 | 236 |
214 if (isRemote() && !m_leaveLocalFile) deleteCacheFile(); | 237 if (isRemote() && !m_leaveLocalFile) deleteCacheFile(); |
595 if (location != "") { | 618 if (location != "") { |
596 QUrl newUrl(location); | 619 QUrl newUrl(location); |
597 if (newUrl != m_url) { | 620 if (newUrl != m_url) { |
598 cleanup(); | 621 cleanup(); |
599 deleteCacheFile(); | 622 deleteCacheFile(); |
623 #ifdef DEBUG_FILE_SOURCE | |
624 decCount(m_url.toString()); | |
625 incCount(newUrl.toString()); | |
626 #endif | |
600 m_url = newUrl; | 627 m_url = newUrl; |
601 m_localFile = 0; | 628 m_localFile = 0; |
602 m_lastStatus = 0; | 629 m_lastStatus = 0; |
603 m_done = false; | 630 m_done = false; |
604 m_refCounted = false; | 631 m_refCounted = false; |