From e198d9bf0c346122667953daed5fce09a5d1118c Mon Sep 17 00:00:00 2001 From: Richard Kettelerij Date: Mon, 16 Oct 2023 19:50:28 +0200 Subject: [PATCH] Create a new tempdir for cache since the cachedir is deleted afterwards --- .../datasources/geopackage/backend_cloud.go | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ogc/features/datasources/geopackage/backend_cloud.go b/ogc/features/datasources/geopackage/backend_cloud.go index dbb3fb3d..25280089 100644 --- a/ogc/features/datasources/geopackage/backend_cloud.go +++ b/ogc/features/datasources/geopackage/backend_cloud.go @@ -12,7 +12,10 @@ import ( "github.com/jmoiron/sqlx" ) -const vfsName = "cloudbackedvfs" +const ( + vfsName = "cloudbackedvfs" + tempDirName = "gokoala" +) // Cloud-Backed SQLite (CBS) GeoPackage in Azure or Google object storage type cloudGeoPackage struct { @@ -21,13 +24,8 @@ type cloudGeoPackage struct { } func newCloudBackedGeoPackage(gpkg *engine.GeoPackageCloud) geoPackageBackend { - cacheDir := os.TempDir() - if gpkg.Cache != nil { - cacheDir = *gpkg.Cache - } - log.Printf("connecting to Cloud-Backed GeoPackage: %s\n", gpkg.Connection) - vfs, err := cloudsqlitevfs.NewVFS(vfsName, gpkg.Connection, gpkg.User, gpkg.Auth, gpkg.Container, cacheDir) + vfs, err := cloudsqlitevfs.NewVFS(vfsName, gpkg.Connection, gpkg.User, gpkg.Auth, gpkg.Container, getCacheDir(gpkg)) if err != nil { log.Fatalf("failed to connect with Cloud-Backed GeoPackage: %v", err) } @@ -41,6 +39,18 @@ func newCloudBackedGeoPackage(gpkg *engine.GeoPackageCloud) geoPackageBackend { return &cloudGeoPackage{db, &vfs} } +func getCacheDir(gpkg *engine.GeoPackageCloud) string { + if gpkg.Cache != nil { + return *gpkg.Cache + } else { + cacheDir, err := os.MkdirTemp("", tempDirName) + if err != nil { + log.Fatalf("failed to create tempdir %s, error %v", tempDirName, err) + } + return cacheDir + } +} + func (g *cloudGeoPackage) getDB() *sqlx.DB { return g.db }