KSPaths writable locations
KSPaths::writableLocation
does not use the current application name when determining the filesystem location where it may write data to.
class KSPaths
{
public:
static QString locate(QStandardPaths::StandardLocation location, const QString &fileName,
QStandardPaths::LocateOptions options = QStandardPaths::LocateFile);
static QStringList locateAll(QStandardPaths::StandardLocation, const QString &fileNames,
QStandardPaths::LocateOptions options = QStandardPaths::LocateFile);
static inline QString writableLocation(QStandardPaths::StandardLocation type)
{
#ifdef Q_OS_ANDROID
if (type == QStandardPaths::GenericDataLocation) {
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
}
#endif
return QStandardPaths::writableLocation(type) + "/kstars/";
}
};
There is indeed a special case for Q_OS_ANDROID
for QStandardPaths::AppDataLocation
as this system will not allow applications to access anything else than what is allowed. Is there any point in doing different for other systems?
Of course, when KSPaths::writableLocation
is called with QStandardPaths::GenericDataLocation
, we end up with ~/.local/share
under linux for instance, and this is not where we should store data. This is probably the reason for the suffix. But in this case, we should not allow to write anything there and use QStandardPaths::AppDataLocation
instead.
This also prevents tests from running independently. Catalog data, for instance, is stored in ~/.qttest/share/kstars
(QStandardPaths::GenericDataLocation
being applied KSPaths::writableLocation
), and is the same for all tests. It is therefore not possible to run tests in parallel and expect persistence separation:
QString dbfile = KSPaths::locate(QStandardPaths::GenericDataLocation, QString("skycomponents.sqlite"));
if (dbfile.isEmpty())
dbfile = KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + QString("skycomponents.sqlite");
Same at other places, such as log storage:
qint64 totalSize = getDirSize(KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "logs");
totalSize += getDirSize(KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "autofocus");
Or Dark Library:
QDir writableDir;
writableDir.mkdir(KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "darks");
writableDir.mkdir(KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "defectmaps");
It is actually the same for all KStars modules. Would there be any harm to replace all occurrences of QStandardPaths::GenericDataLocation
with QStandardPaths::AppDataLocation
when modules call KSPaths::writableLocation
?