# HG changeset patch # User Chris Cannam # Date 1225131320 0 # Node ID c9b055f843265ecb328d8885a494c6cd022a9adc # Parent f35bfa88f0b53c3bc0b5b40feec21a354fbe13e4 * make use of CachedFile (untested) diff -r f35bfa88f0b5 -r c9b055f84326 data/fileio/CachedFile.cpp --- a/data/fileio/CachedFile.cpp Mon Oct 27 15:07:35 2008 +0000 +++ b/data/fileio/CachedFile.cpp Mon Oct 27 18:15:20 2008 +0000 @@ -61,13 +61,30 @@ return fi.filePath(); } -CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) : +CachedFile::CachedFile(QString url, ProgressReporter *reporter) : m_url(url), - m_localFilename(getLocalFilenameFor(url)), + m_localFilename(getLocalFilenameFor(m_url)), m_reporter(reporter), m_ok(false) { - refresh(); + std::cerr << "CachedFile::CachedFile: url is \"" + << url.toStdString() << "\"" << std::endl; + check(); +} + +CachedFile::CachedFile(QUrl url, ProgressReporter *reporter) : + m_url(url), + m_localFilename(getLocalFilenameFor(m_url)), + m_reporter(reporter), + m_ok(false) +{ + std::cerr << "CachedFile::CachedFile: url is \"" + << url.toString().toStdString() << "\"" << std::endl; + check(); +} + +CachedFile::~CachedFile() +{ } bool @@ -83,7 +100,7 @@ } void -CachedFile::refresh() +CachedFile::check() { //!!! n.b. obvious race condition here if different CachedFile // objects for same url used in more than one thread -- need to @@ -91,16 +108,20 @@ // separate instances of the program if (!QFileInfo(m_localFilename).exists()) { + std::cerr << "CachedFile::check: Local file does not exist, making a note that it hasn't been retrieved" << std::endl; updateLastRetrieval(false); // empirically! } QDateTime lastRetrieval = getLastRetrieval(); if (lastRetrieval.isValid()) { + std::cerr << "CachedFile::check: Valid last retrieval at " + << lastRetrieval.toString().toStdString() << std::endl; // this will not be the case if the file is missing, after // updateLastRetrieval(false) was called above m_ok = true; if (lastRetrieval.addDays(2) < QDateTime::currentDateTime()) { //!!! + std::cerr << "CachedFile::check: Out of date; trying to retrieve again" << std::endl; // doesn't matter if retrieval fails -- we just don't // update the last retrieval time @@ -109,15 +130,21 @@ // retrieval every single time if it isn't working if (retrieve()) { + std::cerr << "CachedFile::check: Retrieval succeeded" << std::endl; updateLastRetrieval(true); - } + } else { + std::cerr << "CachedFile::check: Retrieval failed, will try again later (using existing file for now)" << std::endl; + } } } else { + std::cerr << "CachedFile::check: No valid last retrieval" << std::endl; // there is no acceptable file if (retrieve()) { + std::cerr << "CachedFile::check: Retrieval succeeded" << std::endl; m_ok = true; updateLastRetrieval(true); } else { + std::cerr << "CachedFile::check: Retrieval failed, remaining in invalid state" << std::endl; // again, we don't need to do anything here -- the last // retrieval timestamp is already invalid } diff -r f35bfa88f0b5 -r c9b055f84326 data/fileio/CachedFile.h --- a/data/fileio/CachedFile.h Mon Oct 27 15:07:35 2008 +0000 +++ b/data/fileio/CachedFile.h Mon Oct 27 18:15:20 2008 +0000 @@ -25,6 +25,7 @@ class CachedFile { public: + CachedFile(QString fileOrUrl, ProgressReporter *reporter = 0); CachedFile(QUrl url, ProgressReporter *reporter = 0); virtual ~CachedFile(); @@ -39,7 +40,7 @@ ProgressReporter *m_reporter; bool m_ok; - void refresh(); + void check(); bool retrieve(); QDateTime getLastRetrieval(); diff -r f35bfa88f0b5 -r c9b055f84326 rdf/PluginRDFIndexer.cpp --- a/rdf/PluginRDFIndexer.cpp Mon Oct 27 15:07:35 2008 +0000 +++ b/rdf/PluginRDFIndexer.cpp Mon Oct 27 18:15:20 2008 +0000 @@ -17,7 +17,8 @@ #include "SimpleSPARQLQuery.h" -#include "data/fileio/FileSource.h" +//!!!#include "data/fileio/FileSource.h" +#include "data/fileio/CachedFile.h" #include "data/fileio/PlaylistFileReader.h" #include "plugin/PluginIdentifier.h" @@ -100,11 +101,12 @@ PluginRDFIndexer::~PluginRDFIndexer() { QMutexLocker locker(&m_mutex); - +/*!!! while (!m_sources.empty()) { delete *m_sources.begin(); m_sources.erase(m_sources.begin()); } +*/ } bool @@ -125,11 +127,18 @@ std::cerr << "PluginRDFIndexer::indexConfiguredURLs: index url is " << index.toStdString() << std::endl; +/*!!! expireCacheMaybe(index); FileSource indexSource(index, 0, FileSource::PersistentCache); if (!indexSource.isAvailable()) continue; indexSource.waitForData(); +*/ + + CachedFile cf(index); + if (!cf.isOK()) continue; + + FileSource indexSource(cf.getLocalFilename()); PlaylistFileReader reader(indexSource); if (!reader.isOK()) continue; @@ -230,7 +239,7 @@ QString urlString = url.toString(); return indexURL(urlString); } - +/*!!! void PluginRDFIndexer::expireCacheMaybe(QString urlString) { @@ -266,7 +275,7 @@ settings.endGroup(); } - +*/ bool PluginRDFIndexer::indexURL(QString urlString) { @@ -284,6 +293,13 @@ //!!! how do we avoid hammering the server if it doesn't have //!!! the file, and/or the network if it can't get through? + CachedFile cf(urlString); + if (!cf.isOK()) { + return false; + } + + localString = cf.getLocalFilename(); +/*!!! expireCacheMaybe(urlString); FileSource *source = new FileSource @@ -295,6 +311,7 @@ source->waitForData(); localString = QUrl::fromLocalFile(source->getLocalFilename()).toString(); m_sources.insert(source); +*/ } // cerr << "PluginRDFIndexer::indexURL: url = <" << urlString.toStdString() << ">" << endl; diff -r f35bfa88f0b5 -r c9b055f84326 rdf/PluginRDFIndexer.h --- a/rdf/PluginRDFIndexer.h Mon Oct 27 15:07:35 2008 +0000 +++ b/rdf/PluginRDFIndexer.h Mon Oct 27 18:15:20 2008 +0000 @@ -22,7 +22,7 @@ #include #include -class FileSource; +//!!!class FileSource; class PluginRDFIndexer { @@ -55,14 +55,16 @@ protected: PluginRDFIndexer(); QMutex m_mutex; +/*!!! std::set m_sources; +*/ typedef std::map StringMap; StringMap m_uriToIdMap; StringMap m_idToUriMap; StringMap m_idToDescriptionMap; bool indexFile(QString path); static PluginRDFIndexer *m_instance; - void expireCacheMaybe(QString); +//!!! void expireCacheMaybe(QString); }; #endif