diff --git a/.github/workflows/test-infrastructure-files.yml b/.github/workflows/test-infrastructure-files.yml index 8badb5b9bab..ee9739e09eb 100644 --- a/.github/workflows/test-infrastructure-files.yml +++ b/.github/workflows/test-infrastructure-files.yml @@ -162,6 +162,13 @@ jobs: test $count -eq 4 working-directory: infrastructure_files/artifacts + - name: test geolocation databases + working-directory: infrastructure_files/artifacts + run: | + sleep 30 + docker compose exec management ls -l /var/lib/netbird/ | grep -i GeoLite2-City.mmdb + docker compose exec management ls -l /var/lib/netbird/ | grep -i geonames.db + test-getting-started-script: runs-on: ubuntu-latest steps: diff --git a/management/server/geolocation/database.go b/management/server/geolocation/database.go index adf89b28267..1bada60758d 100644 --- a/management/server/geolocation/database.go +++ b/management/server/geolocation/database.go @@ -3,6 +3,7 @@ package geolocation import ( "encoding/csv" "fmt" + "io" "net/url" "os" "path" @@ -35,7 +36,7 @@ func loadGeolocationDatabases(dataDir string) error { if err := decompressTarGzFile(src, dst); err != nil { return err } - return os.Rename(path.Join(dst, MMDBFileName), path.Join(dataDir, MMDBFileName)) + return copyFile(path.Join(dst, MMDBFileName), path.Join(dataDir, MMDBFileName)) } if err := loadDatabase( geoLiteCitySha256TarURL, @@ -185,3 +186,25 @@ func getDatabaseFileName(urlStr string) string { fileName := fmt.Sprintf("%s.%s", path.Base(u.Path), ext) return fileName } + +// copyFile performs a file copy operation from the source file to the destination. +func copyFile(src string, dst string) error { + srcFile, err := os.Open(src) + if err != nil { + return err + } + defer srcFile.Close() + + dstFile, err := os.Create(dst) + if err != nil { + return err + } + defer dstFile.Close() + + _, err = io.Copy(dstFile, srcFile) + if err != nil { + return err + } + + return nil +}