Skip to content

Commit 38e02f7

Browse files
committed
Fix invalid cross-device link when move geonames db
1 parent b085419 commit 38e02f7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

management/server/geolocation/database.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package geolocation
33
import (
44
"encoding/csv"
55
"fmt"
6+
"io"
67
"net/url"
78
"os"
89
"path"
@@ -35,7 +36,7 @@ func loadGeolocationDatabases(dataDir string) error {
3536
if err := decompressTarGzFile(src, dst); err != nil {
3637
return err
3738
}
38-
return os.Rename(path.Join(dst, MMDBFileName), path.Join(dataDir, MMDBFileName))
39+
return copyFile(path.Join(dst, MMDBFileName), path.Join(dataDir, MMDBFileName))
3940
}
4041
if err := loadDatabase(
4142
geoLiteCitySha256TarURL,
@@ -185,3 +186,25 @@ func getDatabaseFileName(urlStr string) string {
185186
fileName := fmt.Sprintf("%s.%s", path.Base(u.Path), ext)
186187
return fileName
187188
}
189+
190+
// copyFile performs a file copy operation from the source file to the destination.
191+
func copyFile(src string, dst string) error {
192+
srcFile, err := os.Open(src)
193+
if err != nil {
194+
return err
195+
}
196+
defer srcFile.Close()
197+
198+
dstFile, err := os.Create(dst)
199+
if err != nil {
200+
return err
201+
}
202+
defer dstFile.Close()
203+
204+
_, err = io.Copy(dstFile, srcFile)
205+
if err != nil {
206+
return err
207+
}
208+
209+
return nil
210+
}

0 commit comments

Comments
 (0)