comparison data/fileio/CachedFile.cpp @ 687:06f13a3b9e9e debug-output

Convert many cerrs to DEBUGs
author Chris Cannam
date Mon, 16 May 2011 17:19:09 +0100
parents b4a8d8221eaf
children 1424aa29ae95
comparison
equal deleted inserted replaced
686:b4a8d8221eaf 687:06f13a3b9e9e
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 std::cerr << "CachedFile::CachedFile: origin is \"" 81 DEBUG << "CachedFile::CachedFile: origin is \""
82 << origin << "\"" << std::endl; 82 << origin << "\"" << endl;
83 check(); 83 check();
84 } 84 }
85 85
86 CachedFile::CachedFile(QUrl url, 86 CachedFile::CachedFile(QUrl url,
87 ProgressReporter *reporter, 87 ProgressReporter *reporter,
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 std::cerr << "CachedFile::CachedFile: url is \"" 96 DEBUG << "CachedFile::CachedFile: url is \""
97 << url.toString() << "\"" << std::endl; 97 << url.toString() << "\"" << endl;
98 check(); 98 check();
99 } 99 }
100 100
101 CachedFile::~CachedFile() 101 CachedFile::~CachedFile()
102 { 102 {
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 std::cerr << "CachedFile::check: Local file does not exist, making a note that it hasn't been retrieved" << std::endl; 135 DEBUG << "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 std::cerr << "CachedFile::check: Valid last retrieval at " 142 DEBUG << "CachedFile::check: Valid last retrieval at "
143 << lastRetrieval.toString() << std::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 std::cerr << "CachedFile::check: Out of date; trying to retrieve again" << std::endl; 148 DEBUG << "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 std::cerr << "CachedFile::check: Retrieval succeeded" << std::endl; 157 DEBUG << "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 std::cerr << "CachedFile::check: No valid last retrieval" << std::endl; 164 DEBUG << "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 std::cerr << "CachedFile::check: Retrieval succeeded" << std::endl; 167 DEBUG << "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 std::cerr << "CachedFile::retrieve: ERROR: FileSource reported unavailable or failure" << std::endl; 194 DEBUG << "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 std::cerr << "CachedFile::retrieve: ERROR: FileSource reported failure during receive" << std::endl; 201 DEBUG << "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 std::cerr << "CachedFile::retrieve: ERROR: FileSource reported success, but local temporary file \"" << tempName << "\" does not exist" << std::endl; 208 DEBUG << "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 std::cerr << "CachedFile::retrieve: Successfully copied newly retrieved file \"" << tempName << "\" to its home at \"" << m_localFilename << "\"" << std::endl; 229 DEBUG << "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