mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Fri Jul 25 20:44:25 CEST 2025
This commit is contained in:
@@ -73,7 +73,7 @@ func (u *CoreUpdater) Update(currentExePath string) (err error) {
|
||||
u.mu.Lock()
|
||||
defer u.mu.Unlock()
|
||||
|
||||
_, err = os.Stat(currentExePath)
|
||||
info, err := os.Stat(currentExePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("check currentExePath %q: %w", currentExePath, err)
|
||||
}
|
||||
@@ -92,7 +92,8 @@ func (u *CoreUpdater) Update(currentExePath string) (err error) {
|
||||
log.Infoln("current version %s, latest version %s", C.Version, latestVersion)
|
||||
|
||||
if latestVersion == C.Version {
|
||||
return fmt.Errorf("update error: %s is the latest version", C.Version)
|
||||
// don't change this output, some downstream dependencies on the upgrader's output fields
|
||||
return fmt.Errorf("update error: already using latest version %s", C.Version)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -145,6 +146,8 @@ func (u *CoreUpdater) Update(currentExePath string) (err error) {
|
||||
return fmt.Errorf("backuping: %w", err)
|
||||
}
|
||||
|
||||
_ = os.Chmod(updateExePath, info.Mode())
|
||||
|
||||
err = u.replace(updateExePath, currentExePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("replacing: %w", err)
|
||||
@@ -276,7 +279,7 @@ func (u *CoreUpdater) clean(updateDir string) {
|
||||
// Existing files are overwritten
|
||||
// All files are created inside outDir, subdirectories are not created
|
||||
// Return the output file name
|
||||
func (u *CoreUpdater) gzFileUnpack(gzfile, outDir string) (string, error) {
|
||||
func (u *CoreUpdater) gzFileUnpack(gzfile, outDir string) (outputName string, err error) {
|
||||
f, err := os.Open(gzfile)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("os.Open(): %w", err)
|
||||
@@ -308,14 +311,10 @@ func (u *CoreUpdater) gzFileUnpack(gzfile, outDir string) (string, error) {
|
||||
originalName = strings.TrimSuffix(originalName, ".gz")
|
||||
}
|
||||
|
||||
outputName := filepath.Join(outDir, originalName)
|
||||
outputName = filepath.Join(outDir, originalName)
|
||||
|
||||
// Create the output file
|
||||
wc, err := os.OpenFile(
|
||||
outputName,
|
||||
os.O_WRONLY|os.O_CREATE|os.O_TRUNC,
|
||||
0o755,
|
||||
)
|
||||
wc, err := os.OpenFile(outputName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("os.OpenFile(%s): %w", outputName, err)
|
||||
}
|
||||
@@ -340,7 +339,7 @@ func (u *CoreUpdater) gzFileUnpack(gzfile, outDir string) (string, error) {
|
||||
// Existing files are overwritten
|
||||
// All files are created inside 'outDir', subdirectories are not created
|
||||
// Return the output file name
|
||||
func (u *CoreUpdater) zipFileUnpack(zipfile, outDir string) (string, error) {
|
||||
func (u *CoreUpdater) zipFileUnpack(zipfile, outDir string) (outputName string, err error) {
|
||||
zrc, err := zip.OpenReader(zipfile)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("zip.OpenReader(): %w", err)
|
||||
@@ -372,7 +371,7 @@ func (u *CoreUpdater) zipFileUnpack(zipfile, outDir string) (string, error) {
|
||||
}()
|
||||
fi := zf.FileInfo()
|
||||
name := fi.Name()
|
||||
outputName := filepath.Join(outDir, name)
|
||||
outputName = filepath.Join(outDir, name)
|
||||
|
||||
if fi.IsDir() {
|
||||
return "", fmt.Errorf("the target file is a directory")
|
||||
@@ -399,14 +398,38 @@ func (u *CoreUpdater) zipFileUnpack(zipfile, outDir string) (string, error) {
|
||||
}
|
||||
|
||||
// Copy file on disk
|
||||
func (u *CoreUpdater) copyFile(src, dst string) error {
|
||||
d, e := os.ReadFile(src)
|
||||
if e != nil {
|
||||
return e
|
||||
func (u *CoreUpdater) copyFile(src, dst string) (err error) {
|
||||
rc, err := os.Open(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("os.Open(%s): %w", src, err)
|
||||
}
|
||||
e = os.WriteFile(dst, d, 0o644)
|
||||
if e != nil {
|
||||
return e
|
||||
|
||||
defer func() {
|
||||
closeErr := rc.Close()
|
||||
if closeErr != nil && err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
}()
|
||||
|
||||
// Create the output file
|
||||
// If the file does not exist, creates it with permissions perm (before umask);
|
||||
// otherwise truncates it before writing, without changing permissions.
|
||||
wc, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("os.OpenFile(%s): %w", dst, err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
closeErr := wc.Close()
|
||||
if closeErr != nil && err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = io.Copy(wc, rc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("io.Copy(): %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func UpdateGeoDatabases() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getUpdateTime() (err error, time time.Time) {
|
||||
func getUpdateTime() (time time.Time, err error) {
|
||||
filesToCheck := []string{
|
||||
C.Path.GeoIP(),
|
||||
C.Path.MMDB(),
|
||||
@@ -224,7 +224,7 @@ func getUpdateTime() (err error, time time.Time) {
|
||||
var fileInfo os.FileInfo
|
||||
fileInfo, err = os.Stat(file)
|
||||
if err == nil {
|
||||
return nil, fileInfo.ModTime()
|
||||
return fileInfo.ModTime(), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ func RegisterGeoUpdater() {
|
||||
ticker := time.NewTicker(time.Duration(updateInterval) * time.Hour)
|
||||
defer ticker.Stop()
|
||||
|
||||
err, lastUpdate := getUpdateTime()
|
||||
lastUpdate, err := getUpdateTime()
|
||||
if err != nil {
|
||||
log.Errorln("[GEO] Get GEO database update time error: %s", err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user