Skip to content

Commit

Permalink
Create a new tempdir for cache since the cachedir is deleted afterwards
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Oct 16, 2023
1 parent 973dcfe commit e198d9b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions ogc/features/datasources/geopackage/backend_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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 {

Check warning on line 45 in ogc/features/datasources/geopackage/backend_cloud.go

View workflow job for this annotation

GitHub Actions / lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
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
}
Expand Down

0 comments on commit e198d9b

Please sign in to comment.