Skip to content

Commit

Permalink
Fix invalid cross-device link when moving geolocation databases (#1638)
Browse files Browse the repository at this point in the history
* Fix invalid cross-device link when move geonames db

* Add test for geolocation databases in workflow

This step checks the existence and proper functioning of geolocation databases, including GeoLite2-City.mmdb and Geonames.db. It will help us ensure that geolocation databases are loaded correctly in the management.

* Enable debug mode

* Increase sleep duration in geolocation tests
  • Loading branch information
bcmmbaga authored Feb 28, 2024
1 parent b085419 commit f64e73c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/test-infrastructure-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 24 additions & 1 deletion management/server/geolocation/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package geolocation
import (
"encoding/csv"
"fmt"
"io"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

0 comments on commit f64e73c

Please sign in to comment.