Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
4779c2ec
Commit
4779c2ec
authored
Sep 05, 2021
by
Volker Krause
Browse files
Implement GBFS cache expiry
parent
acd4b767
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/gbfs/gbfsbackend.cpp
View file @
4779c2ec
...
...
@@ -17,17 +17,23 @@
#include
<KPublicTransport/LocationRequest>
#include
<KPublicTransport/RentalVehicle>
#include
<QCoreApplication>
#include
<QDebug>
#include
<QJsonArray>
#include
<QJsonDocument>
#include
<QJsonObject>
#include
<QTimer>
#include
<cmath>
#include
<functional>
using
namespace
KPublicTransport
;
GBFSBackend
::
GBFSBackend
()
=
default
;
GBFSBackend
::
GBFSBackend
()
{
QTimer
::
singleShot
(
std
::
chrono
::
seconds
(
10
),
Qt
::
CoarseTimer
,
QCoreApplication
::
instance
(),
[]()
{
GBFSStore
::
expire
();
});
}
GBFSBackend
::~
GBFSBackend
()
=
default
;
AbstractBackend
::
Capabilities
GBFSBackend
::
capabilities
()
const
...
...
src/lib/gbfs/gbfsstore.cpp
View file @
4779c2ec
...
...
@@ -5,10 +5,12 @@
*/
#include
"gbfsstore.h"
#include
"logging.h"
#include
<QDateTime>
#include
<QDebug>
#include
<QDir>
#include
<QDirIterator>
#include
<QFile>
#include
<QFileInfo>
#include
<QJsonDocument>
...
...
@@ -97,9 +99,29 @@ QJsonDocument GBFSStore::loadData(GBFS::FileType type) const
return
QJsonDocument
::
fromJson
(
f
.
readAll
());
}
static
void
expireRecursive
(
const
QString
&
path
)
{
const
auto
now
=
QDateTime
::
currentDateTime
();
QDirIterator
it
(
path
,
QDir
::
Files
|
QDir
::
Dirs
|
QDir
::
NoDotAndDotDot
|
QDir
::
NoSymLinks
);
while
(
it
.
hasNext
())
{
it
.
next
();
if
(
it
.
fileInfo
().
isDir
())
{
expireRecursive
(
it
.
filePath
());
if
(
QDir
(
it
.
filePath
()).
isEmpty
())
{
qCDebug
(
Log
)
<<
"removing empty cache directory"
<<
it
.
fileName
();
QDir
(
path
).
rmdir
(
it
.
filePath
());
}
}
else
if
(
it
.
fileInfo
().
lastModified
()
<
now
)
{
qCDebug
(
Log
)
<<
"removing expired cache entry"
<<
it
.
filePath
();
QDir
(
path
).
remove
(
it
.
filePath
());
}
}
}
void
GBFSStore
::
expire
()
{
// TODO
expireRecursive
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericCacheLocation
)
+
QLatin1String
(
"/org.kde.kpublictransport/gbfs/feeds/"
));
}
QString
GBFSStore
::
fileName
(
GBFS
::
FileType
type
)
const
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment