-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Fix the initialization errors of GeoIP #7345
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ func initLang() { | |
downloadGeoFromRemote(fileOp, geoPath) | ||
return | ||
} | ||
std, err := cmd.Execf("cp %s %s/", path.Join(tmpPath, "GeoIP.mmdb"), path.Dir(geoPath)) | ||
std, err := cmd.Execf("mkdir %s && cp %s %s/", path.Dir(geoPath), path.Join(tmpPath, "GeoIP.mmdb"), path.Dir(geoPath)) | ||
if err != nil { | ||
global.LOG.Errorf("load geo ip from package failed, std: %s, err: %v", std, err) | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modified code introduces an unexpected operation that changes the directory structure instead of just copying the file. This is likely incorrect, as it implies changing into the destination directory which isn't needed for copying a file. Additionally, the # Updated Code Snippet: Fixing Directory Issue
func initLang() {
downloadGeoFromRemote(fileOp, geoPath)
return
}
- std, err := cmd.Execf("cp %s %s/", path.Join(tmpPath, "GeoIP.mmdb"), path.Dir(geoPath)) # Remove 'mkdir'
+ std, err := cmd.Execf("cp %s %s", path.Join(tmpPath, "GeoIP.mmdb"), path.Dir(geoPath)) # Correct command without mkdir
if err != nil {
global.LOG.Errorf("load geo ip from package failed, std: %s, err: %v", std, err)
return
} Changes Made:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,8 @@ var restoreCmd = &cobra.Command{ | |
return err | ||
} | ||
_, _ = cmdUtils.Execf("cp -r %s /usr/local/bin", path.Join(tmpPath, "lang")) | ||
_, _ = cmdUtils.Execf("cp %s %s", path.Join(tmpPath, "GeoIP.mmdb"), path.Join(global.CONF.System.BaseDir, "1panel/geo/")) | ||
geoPath := path.Join(global.CONF.System.BaseDir, "1panel/geo") | ||
_, _ = cmdUtils.Execf("mkdir %s && cp %s %s/", geoPath, path.Join(tmpPath, "GeoIP.mmdb"), geoPath) | ||
fmt.Println(i18n.GetMsgByKeyForCmd("RestoreStep3")) | ||
if err := common.CopyFile(path.Join(tmpPath, "1panel.service"), "/etc/systemd/system"); err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code snippet includes several minor improvements:
Here are your original changes with notes marked: @@ -55,7 +55,6 @@ var restoreCmd = &cobra.Command{
- return err
}
if _, err := cmdUtils.Execf("cp -r %s /usr/local/bin", path.Join(tmpPath, "lang")); err != nil {
@@ -57,6 +56,9 @@
fmt.Println(i18n.GetMsgByKeyForCmd("RestoreStep3"))
+ // Create the destination directory if it doesn't exist
+ err := os.MkdirAll(geoPath, 0o755) // Assuming you want user/group writable
+ if err != nil {
+ return err
+ }
+
if err := common.CopyFile(geoservicefileTemp, "/etc/systemd/system"); err != nil {
return err If there were intended conditions that would only apply under different scenarios or error situations where some operations might not need execution (e.g., already exists checks before creating directories), those should also be addressed in the updated code. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code has two main differences:
The second
cp
command creates the directory/usr/local/bin/lang
first before copying the file, which might not be necessary if you're trying to copy over an existing file.No error handling is included for creating directories or copying files, which can lead to runtime errors if conditions are met but actions fail unexpectedly.
Additionally, you should always handle errors explicitly when calling external commands to avoid silently ignoring them. Here's a revised version with improvements and suggested changes:
Changes made:
os.MkdirAll()
is used to attempt creating the/usr/local/bin/lang
directory.