comparison data/fileio/CachedFile.cpp @ 468:70b333085952

* complete switching the code to use CachedFile -- now to tidy & fix the remaining flaws...
author Chris Cannam
date Mon, 27 Oct 2008 20:29:55 +0000
parents c9b055f84326
children a82645e788fc
comparison
equal deleted inserted replaced
467:c9b055f84326 468:70b333085952
59 } 59 }
60 60
61 return fi.filePath(); 61 return fi.filePath();
62 } 62 }
63 63
64 CachedFile::CachedFile(QString url, ProgressReporter *reporter) : 64 CachedFile::CachedFile(QString origin, ProgressReporter *reporter) :
65 m_url(url), 65 m_origin(origin),
66 m_localFilename(getLocalFilenameFor(m_url)), 66 m_localFilename(getLocalFilenameFor(m_origin)),
67 m_reporter(reporter), 67 m_reporter(reporter),
68 m_ok(false) 68 m_ok(false)
69 { 69 {
70 std::cerr << "CachedFile::CachedFile: url is \"" 70 std::cerr << "CachedFile::CachedFile: origin is \""
71 << url.toStdString() << "\"" << std::endl; 71 << origin.toStdString() << "\"" << std::endl;
72 check(); 72 check();
73 } 73 }
74 74
75 CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) : 75 CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) :
76 m_url(url), 76 m_origin(url.toString()),
77 m_localFilename(getLocalFilenameFor(m_url)), 77 m_localFilename(getLocalFilenameFor(m_origin)),
78 m_reporter(reporter), 78 m_reporter(reporter),
79 m_ok(false) 79 m_ok(false)
80 { 80 {
81 std::cerr << "CachedFile::CachedFile: url is \"" 81 std::cerr << "CachedFile::CachedFile: url is \""
82 << url.toString().toStdString() << "\"" << std::endl; 82 << url.toString().toStdString() << "\"" << std::endl;
158 //!!! then "atomically" moving it to its proper place (I'm not 158 //!!! then "atomically" moving it to its proper place (I'm not
159 //!!! sure we can do an atomic move to replace an existing file 159 //!!! sure we can do an atomic move to replace an existing file
160 //!!! using Qt classes, but a plain delete then copy is probably 160 //!!! using Qt classes, but a plain delete then copy is probably
161 //!!! good enough) 161 //!!! good enough)
162 162
163 FileSource fs(m_url, m_reporter); 163 FileSource fs(m_origin, m_reporter);
164 164
165 if (!fs.isOK() || !fs.isAvailable()) { 165 if (!fs.isOK() || !fs.isAvailable()) {
166 std::cerr << "CachedFile::retrieve: ERROR: FileSource reported unavailable or failure" << std::endl;
166 return false; 167 return false;
167 } 168 }
168 169
169 fs.waitForData(); 170 fs.waitForData();
170 171
171 if (!fs.isOK()) { 172 if (!fs.isOK()) {
173 std::cerr << "CachedFile::retrieve: ERROR: FileSource reported failure during receive" << std::endl;
172 return false; 174 return false;
173 } 175 }
174 176
175 QString tempName = fs.getLocalFilename(); 177 QString tempName = fs.getLocalFilename();
176 QFile tempFile(tempName); 178 QFile tempFile(tempName);
194 if (!tempFile.copy(m_localFilename)) { 196 if (!tempFile.copy(m_localFilename)) {
195 std::cerr << "CachedFile::retrieve: ERROR: Failed to copy newly retrieved file from \"" << tempName.toStdString() << "\" to \"" << m_localFilename.toStdString() << "\"" << std::endl; 197 std::cerr << "CachedFile::retrieve: ERROR: Failed to copy newly retrieved file from \"" << tempName.toStdString() << "\" to \"" << m_localFilename.toStdString() << "\"" << std::endl;
196 return false; 198 return false;
197 } 199 }
198 200
201 std::cerr << "CachedFile::retrieve: Successfully copied newly retrieved file \"" << tempName.toStdString() << "\" to its home at \"" << m_localFilename.toStdString() << "\"" << std::endl;
202
199 return true; 203 return true;
200 } 204 }
201 205
202 QDateTime 206 QDateTime
203 CachedFile::getLastRetrieval() 207 CachedFile::getLastRetrieval()