Mercurial > hg > svcore
comparison data/fileio/CachedFile.cpp @ 690:1424aa29ae95
Seems to be a bad idea to use plain DEBUG symbol on OS/X (system wants it)
author | Chris Cannam |
---|---|
date | Tue, 14 Jun 2011 15:26:52 +0100 |
parents | 06f13a3b9e9e |
children | b99dc5465b80 |
comparison
equal
deleted
inserted
replaced
689:573d45e9487b | 690:1424aa29ae95 |
---|---|
76 m_reporter(reporter), | 76 m_reporter(reporter), |
77 m_ok(false) | 77 m_ok(false) |
78 { | 78 { |
79 Profiler p("CachedFile::CachedFile[1]"); | 79 Profiler p("CachedFile::CachedFile[1]"); |
80 | 80 |
81 DEBUG << "CachedFile::CachedFile: origin is \"" | 81 SVDEBUG << "CachedFile::CachedFile: origin is \"" |
82 << origin << "\"" << endl; | 82 << origin << "\"" << endl; |
83 check(); | 83 check(); |
84 } | 84 } |
85 | 85 |
86 CachedFile::CachedFile(QUrl url, | 86 CachedFile::CachedFile(QUrl url, |
91 m_reporter(reporter), | 91 m_reporter(reporter), |
92 m_ok(false) | 92 m_ok(false) |
93 { | 93 { |
94 Profiler p("CachedFile::CachedFile[2]"); | 94 Profiler p("CachedFile::CachedFile[2]"); |
95 | 95 |
96 DEBUG << "CachedFile::CachedFile: url is \"" | 96 SVDEBUG << "CachedFile::CachedFile: url is \"" |
97 << url.toString() << "\"" << endl; | 97 << url.toString() << "\"" << endl; |
98 check(); | 98 check(); |
99 } | 99 } |
100 | 100 |
101 CachedFile::~CachedFile() | 101 CachedFile::~CachedFile() |
130 } | 130 } |
131 | 131 |
132 m_localFilename = getLocalFilenameFor(m_origin); | 132 m_localFilename = getLocalFilenameFor(m_origin); |
133 | 133 |
134 if (!QFileInfo(m_localFilename).exists()) { | 134 if (!QFileInfo(m_localFilename).exists()) { |
135 DEBUG << "CachedFile::check: Local file does not exist, making a note that it hasn't been retrieved" << endl; | 135 SVDEBUG << "CachedFile::check: Local file does not exist, making a note that it hasn't been retrieved" << endl; |
136 updateLastRetrieval(false); // empirically! | 136 updateLastRetrieval(false); // empirically! |
137 } | 137 } |
138 | 138 |
139 QDateTime lastRetrieval = getLastRetrieval(); | 139 QDateTime lastRetrieval = getLastRetrieval(); |
140 | 140 |
141 if (lastRetrieval.isValid()) { | 141 if (lastRetrieval.isValid()) { |
142 DEBUG << "CachedFile::check: Valid last retrieval at " | 142 SVDEBUG << "CachedFile::check: Valid last retrieval at " |
143 << lastRetrieval.toString() << endl; | 143 << lastRetrieval.toString() << endl; |
144 // this will not be the case if the file is missing, after | 144 // this will not be the case if the file is missing, after |
145 // updateLastRetrieval(false) was called above | 145 // updateLastRetrieval(false) was called above |
146 m_ok = true; | 146 m_ok = true; |
147 if (lastRetrieval.addDays(2) < QDateTime::currentDateTime()) { //!!! | 147 if (lastRetrieval.addDays(2) < QDateTime::currentDateTime()) { //!!! |
148 DEBUG << "CachedFile::check: Out of date; trying to retrieve again" << endl; | 148 SVDEBUG << "CachedFile::check: Out of date; trying to retrieve again" << endl; |
149 // doesn't matter if retrieval fails -- we just don't | 149 // doesn't matter if retrieval fails -- we just don't |
150 // update the last retrieval time | 150 // update the last retrieval time |
151 | 151 |
152 //!!! but we do want an additional last-attempted | 152 //!!! but we do want an additional last-attempted |
153 // timestamp so as to ensure we aren't retrying the | 153 // timestamp so as to ensure we aren't retrying the |
154 // retrieval every single time if it isn't working | 154 // retrieval every single time if it isn't working |
155 | 155 |
156 if (retrieve()) { | 156 if (retrieve()) { |
157 DEBUG << "CachedFile::check: Retrieval succeeded" << endl; | 157 SVDEBUG << "CachedFile::check: Retrieval succeeded" << endl; |
158 updateLastRetrieval(true); | 158 updateLastRetrieval(true); |
159 } else { | 159 } else { |
160 std::cerr << "CachedFile::check: Retrieval failed, will try again later (using existing file for now)" << std::endl; | 160 std::cerr << "CachedFile::check: Retrieval failed, will try again later (using existing file for now)" << std::endl; |
161 } | 161 } |
162 } | 162 } |
163 } else { | 163 } else { |
164 DEBUG << "CachedFile::check: No valid last retrieval" << endl; | 164 SVDEBUG << "CachedFile::check: No valid last retrieval" << endl; |
165 // there is no acceptable file | 165 // there is no acceptable file |
166 if (retrieve()) { | 166 if (retrieve()) { |
167 DEBUG << "CachedFile::check: Retrieval succeeded" << endl; | 167 SVDEBUG << "CachedFile::check: Retrieval succeeded" << endl; |
168 m_ok = true; | 168 m_ok = true; |
169 updateLastRetrieval(true); | 169 updateLastRetrieval(true); |
170 } else { | 170 } else { |
171 std::cerr << "CachedFile::check: Retrieval failed, remaining in invalid state" << std::endl; | 171 std::cerr << "CachedFile::check: Retrieval failed, remaining in invalid state" << std::endl; |
172 // again, we don't need to do anything here -- the last | 172 // again, we don't need to do anything here -- the last |
189 //!!! good enough) | 189 //!!! good enough) |
190 | 190 |
191 FileSource fs(m_origin, m_reporter, m_preferredContentType); | 191 FileSource fs(m_origin, m_reporter, m_preferredContentType); |
192 | 192 |
193 if (!fs.isOK() || !fs.isAvailable()) { | 193 if (!fs.isOK() || !fs.isAvailable()) { |
194 DEBUG << "CachedFile::retrieve: ERROR: FileSource reported unavailable or failure" << endl; | 194 SVDEBUG << "CachedFile::retrieve: ERROR: FileSource reported unavailable or failure" << endl; |
195 return false; | 195 return false; |
196 } | 196 } |
197 | 197 |
198 fs.waitForData(); | 198 fs.waitForData(); |
199 | 199 |
200 if (!fs.isOK()) { | 200 if (!fs.isOK()) { |
201 DEBUG << "CachedFile::retrieve: ERROR: FileSource reported failure during receive" << endl; | 201 SVDEBUG << "CachedFile::retrieve: ERROR: FileSource reported failure during receive" << endl; |
202 return false; | 202 return false; |
203 } | 203 } |
204 | 204 |
205 QString tempName = fs.getLocalFilename(); | 205 QString tempName = fs.getLocalFilename(); |
206 QFile tempFile(tempName); | 206 QFile tempFile(tempName); |
207 if (!tempFile.exists()) { | 207 if (!tempFile.exists()) { |
208 DEBUG << "CachedFile::retrieve: ERROR: FileSource reported success, but local temporary file \"" << tempName << "\" does not exist" << endl; | 208 SVDEBUG << "CachedFile::retrieve: ERROR: FileSource reported success, but local temporary file \"" << tempName << "\" does not exist" << endl; |
209 return false; | 209 return false; |
210 } | 210 } |
211 | 211 |
212 QFile previous(m_localFilename); | 212 QFile previous(m_localFilename); |
213 if (previous.exists()) { | 213 if (previous.exists()) { |
224 if (!tempFile.copy(m_localFilename)) { | 224 if (!tempFile.copy(m_localFilename)) { |
225 std::cerr << "CachedFile::retrieve: ERROR: Failed to copy newly retrieved file from \"" << tempName << "\" to \"" << m_localFilename << "\"" << std::endl; | 225 std::cerr << "CachedFile::retrieve: ERROR: Failed to copy newly retrieved file from \"" << tempName << "\" to \"" << m_localFilename << "\"" << std::endl; |
226 return false; | 226 return false; |
227 } | 227 } |
228 | 228 |
229 DEBUG << "CachedFile::retrieve: Successfully copied newly retrieved file \"" << tempName << "\" to its home at \"" << m_localFilename << "\"" << endl; | 229 SVDEBUG << "CachedFile::retrieve: Successfully copied newly retrieved file \"" << tempName << "\" to its home at \"" << m_localFilename << "\"" << endl; |
230 | 230 |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 QDateTime | 234 QDateTime |