2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 07:57:21 +08:00

fix: 跨文件系统文件移动优化

This commit is contained in:
耗子
2024-10-14 13:03:16 +08:00
parent 1bea44146f
commit 744d0b9617
5 changed files with 29 additions and 19 deletions

View File

@@ -177,10 +177,18 @@ func (r *settingRepo) UpdatePanelSetting(ctx context.Context, setting *request.P
}
func (r *settingRepo) UpdatePanel(version, url, checksum string) error {
// 预先优化数据库
if err := app.Orm.Exec("VACUUM").Error; err != nil {
return err
}
if err := app.Orm.Exec("PRAGMA wal_checkpoint(TRUNCATE);").Error; err != nil {
return err
}
name := filepath.Base(url)
color.Greenln("目标版本:", version)
color.Greenln("下载链接:", url)
color.Greenln("文件名:", name)
color.Greenln(fmt.Sprintf("目标版本:%s", version))
color.Greenln(fmt.Sprintf("下载链接:%s", url))
color.Greenln(fmt.Sprintf("文件名:%s", name))
color.Greenln("前置检查...")
if io.Exists("/tmp/panel-storage.zip") {

View File

@@ -33,6 +33,10 @@ func (receiver *PanelTask) Run() {
types.Status = types.StatusFailed
app.Logger.Error("优化面板数据库失败", zap.Error(err))
}
if err := app.Orm.Exec("PRAGMA wal_checkpoint(TRUNCATE);").Error; err != nil {
types.Status = types.StatusFailed
app.Logger.Error("优化面板数据库失败", zap.Error(err))
}
// 备份面板
if err := receiver.backupRepo.Create(biz.BackupTypePanel, ""); err != nil {

View File

@@ -191,11 +191,6 @@ func FormatArchiveByPath(path string) (FormatArchive, error) {
}
}
// TempFile 创建临时文件
func TempFile(prefix string) (*os.File, error) {
return os.CreateTemp("", prefix)
}
// IsSymlink 判读是否为软链接
func IsSymlink(mode os.FileMode) bool {
return mode&os.ModeSymlink != 0

View File

@@ -2,6 +2,7 @@ package io
import (
"fmt"
"github.com/TheTNB/panel/pkg/shell"
"io"
"os"
"os/exec"
@@ -49,17 +50,14 @@ func Empty(path string) bool {
}
func Mv(src, dst string) error {
err := os.Rename(src, dst)
if err != nil {
// 如果在不同的文件系统中移动文件os.Rename 可能会失败
err = Cp(src, dst)
if err != nil {
if err := os.Rename(src, dst); err != nil {
// 在不同的文件系统中无法使用os.Rename
if _, err = shell.Execf(`mv -f '%s' '%s'`, src, dst); err != nil {
return err
}
err = os.RemoveAll(src)
}
return err
return nil
}
// Cp 复制文件或目录
@@ -147,6 +145,11 @@ func TempDir(prefix string) (string, error) {
return os.MkdirTemp("", prefix)
}
// TempFile 创建临时文件
func TempFile(dir, prefix string) (*os.File, error) {
return os.CreateTemp(dir, prefix)
}
// ReadDir 读取目录
func ReadDir(path string) ([]os.DirEntry, error) {
return os.ReadDir(path)

View File

@@ -39,7 +39,7 @@ func (p *Parser) Config() *config.Config {
}
// Find 通过表达式查找配置
// eg: Find("server.listen")
// e.g. Find("server.listen")
func (p *Parser) Find(key string) ([]config.IDirective, error) {
parts := strings.Split(key, ".")
var block *config.Block
@@ -71,7 +71,7 @@ func (p *Parser) Find(key string) ([]config.IDirective, error) {
}
// FindOne 通过表达式查找一个配置
// eg: FindOne("server.server_name")
// e.g. FindOne("server.server_name")
func (p *Parser) FindOne(key string) (config.IDirective, error) {
directives, err := p.Find(key)
if err != nil {
@@ -85,7 +85,7 @@ func (p *Parser) FindOne(key string) (config.IDirective, error) {
}
// Clear 通过表达式移除配置
// eg: Clear("server.server_name")
// e.g. Clear("server.server_name")
func (p *Parser) Clear(key string) error {
parts := strings.Split(key, ".")
last := parts[len(parts)-1]
@@ -120,7 +120,7 @@ func (p *Parser) Clear(key string) error {
}
// Set 通过表达式设置配置
// eg: Set("server.server_name", []directive)
// e.g. Set("server.server_name", []directive)
func (p *Parser) Set(key string, directives []*config.Directive) error {
parts := strings.Split(key, ".")