From a42f1f75ad2fb79aaa08debbc1acdcc32946edbb Mon Sep 17 00:00:00 2001 From: alex-osm Date: Thu, 26 Sep 2024 20:43:14 +0300 Subject: [PATCH] Do not put temp gpx files into gpx database --- .../commonMain/kotlin/net/osmand/shared/gpx/GpxDataItem.kt | 7 +++++++ .../commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt | 2 +- .../commonMain/kotlin/net/osmand/shared/gpx/GpxReader.kt | 3 +++ .../kotlin/net/osmand/shared/gpx/GpxUtilities.kt | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDataItem.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDataItem.kt index 2ab1893cd72..0ba8c5ac8c1 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDataItem.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDataItem.kt @@ -2,6 +2,7 @@ package net.osmand.shared.gpx import net.osmand.shared.io.KFile import net.osmand.shared.routing.ColoringType +import net.osmand.shared.util.PlatformUtil class GpxDataItem( file: KFile @@ -9,6 +10,12 @@ class GpxDataItem( private var analysis: GpxTrackAnalysis? = null + companion object { + fun isRegularTrack(file: KFile) = file.path().startsWith(PlatformUtil.getOsmAndContext().getGpxDir().path()) + } + + fun isRegularTrack() = Companion.isRegularTrack(file) + fun getAnalysis(): GpxTrackAnalysis? { return analysis } diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt index 26034ae34c4..a2f635a6d04 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxDbHelper.kt @@ -248,7 +248,7 @@ object GpxDbHelper : GpxReaderAdapter { return null } val item = dataItems[file] - if (GpxDbUtils.isAnalyseNeeded(item)) { + if (GpxDbUtils.isAnalyseNeeded(item) && GpxDataItem.isRegularTrack(file)) { readGpxItem(file, item, callback) } return item diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxReader.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxReader.kt index 4f79184b486..9822ed59cdb 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxReader.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxReader.kt @@ -93,6 +93,9 @@ class GpxReader(private val adapter: GpxReaderAdapter) if (gpxFile.error == null) { val analyser = PlatformUtil.getOsmAndContext().getTrackPointsAnalyser() updatedItem.setAnalysis(gpxFile.getAnalysis(file.lastModified(), null, null, analyser)) + if (!updatedItem.isRegularTrack()) { + return updatedItem + } val creationTime: Long = updatedItem.requireParameter(GpxParameter.FILE_CREATION_TIME) if (creationTime <= 0) { updatedItem.setParameter(GpxParameter.FILE_CREATION_TIME, GpxUtilities.getCreationTime(gpxFile)) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt index 25bd7f59dd4..2ac69d55e8c 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt @@ -974,7 +974,7 @@ object GpxUtilities { gpxFile.modifiedTime = file.lastModified() gpxFile.pointsModifiedTime = gpxFile.modifiedTime if (gpxFile.error != null) { - log.info("Error reading gpx ${gpxFile.path}") + log.info("Error reading gpx ${gpxFile.path}: ${gpxFile.error!!.message}") } gpxFile } catch (e: IOException) {