mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-09 19:20:56 +08:00
fix: Fix the problem that the cache clears deleted log files by mistake (#8135)
This commit is contained in:
parent
ce22f8a2d8
commit
2dfccdd2a9
9 changed files with 45 additions and 17 deletions
|
|
@ -21,6 +21,7 @@ type ITaskRepo interface {
|
||||||
UpdateRunningTaskToFailed() error
|
UpdateRunningTaskToFailed() error
|
||||||
CountExecutingTask() (int64, error)
|
CountExecutingTask() (int64, error)
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...DBOption) error
|
||||||
|
DeleteAll() error
|
||||||
|
|
||||||
WithByID(id string) DBOption
|
WithByID(id string) DBOption
|
||||||
WithResourceID(id uint) DBOption
|
WithResourceID(id uint) DBOption
|
||||||
|
|
@ -118,3 +119,7 @@ func (u TaskRepo) Delete(opts ...DBOption) error {
|
||||||
}
|
}
|
||||||
return db.Delete(&model.Task{}).Error
|
return db.Delete(&model.Task{}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u TaskRepo) DeleteAll() error {
|
||||||
|
return global.TaskDB.Where("1 = 1").Delete(&model.Task{}).Error
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if newBackup.Type == constant.OneDrive || newBackup.Type == constant.GoogleDrive {
|
if newBackup.Type == constant.OneDrive || newBackup.Type == constant.GoogleDrive {
|
||||||
if err := loadRefreshTokenByCode(&backup); err != nil {
|
if err := loadRefreshTokenByCode(&newBackup); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ func (u *DeviceService) Clean(req []dto.Clean) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.Name() == "1Panel.log" || file.IsDir() {
|
if file.Name() == "1Panel-Core.log" || file.Name() == "1Panel.log" || file.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dropFileOrDir(path.Join(global.Dir.BaseDir, logPath, file.Name()))
|
dropFileOrDir(path.Join(global.Dir.BaseDir, logPath, file.Name()))
|
||||||
|
|
@ -253,11 +253,25 @@ func (u *DeviceService) Clean(req []dto.Clean) {
|
||||||
dropFileOrDir(path.Join(global.Dir.BaseDir, logPath, item.Name))
|
dropFileOrDir(path.Join(global.Dir.BaseDir, logPath, item.Name))
|
||||||
}
|
}
|
||||||
case "task_log":
|
case "task_log":
|
||||||
|
if len(item.Name) == 0 {
|
||||||
|
files, _ := os.ReadDir(path.Join(global.Dir.BaseDir, logPath))
|
||||||
|
if len(files) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if file.Name() == "ssl" || !file.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dropFileOrDir(path.Join(global.Dir.BaseDir, logPath, file.Name()))
|
||||||
|
}
|
||||||
|
_ = taskRepo.DeleteAll()
|
||||||
|
} else {
|
||||||
pathItem := path.Join(global.Dir.BaseDir, logPath, item.Name)
|
pathItem := path.Join(global.Dir.BaseDir, logPath, item.Name)
|
||||||
dropFileOrDir(pathItem)
|
dropFileOrDir(pathItem)
|
||||||
if len(item.Name) != 0 {
|
if len(item.Name) != 0 {
|
||||||
_ = taskRepo.Delete(repo.WithByType(item.Name))
|
_ = taskRepo.Delete(repo.WithByType(item.Name))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case "images":
|
case "images":
|
||||||
dropImages()
|
dropImages()
|
||||||
case "containers":
|
case "containers":
|
||||||
|
|
@ -326,7 +340,7 @@ func systemClean(taskItem *task.Task) error {
|
||||||
if logFiles[i].IsDir() {
|
if logFiles[i].IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if logFiles[i].Name() != "1Panel.log" {
|
if logFiles[i].Name() != "1Panel.log" && logFiles[i].Name() != "1Panel-Core.log" {
|
||||||
dropWithTask(path.Join(logPath, logFiles[i].Name()), taskItem, &size, &fileCount)
|
dropWithTask(path.Join(logPath, logFiles[i].Name()), taskItem, &size, &fileCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -591,7 +605,10 @@ func loadTreeWithAllFile(isCheck bool, originalPath, treeType, pathItem string,
|
||||||
return lists
|
return lists
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if treeType == "system_log" && (file.Name() == "1Panel.log" || file.IsDir()) {
|
if treeType == "upload" && (file.Name() == "theme" && file.IsDir()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if treeType == "system_log" && (file.Name() == "1Panel-Core.log" || file.Name() == "1Panel.log" || file.IsDir()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (treeType == "upload" || treeType == "download") && file.IsDir() && (file.Name() == "app" || file.Name() == "database" || file.Name() == "website" || file.Name() == "directory") {
|
if (treeType == "upload" || treeType == "download") && file.IsDir() && (file.Name() == "app" || file.Name() == "database" || file.Name() == "website" || file.Name() == "directory") {
|
||||||
|
|
|
||||||
|
|
@ -247,11 +247,13 @@ func backupBeforeRecover(name string, itemHelper *snapRecoverHelper) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if itemHelper.FileOp.Stat("/etc/docker/daemon.json") {
|
||||||
err = itemHelper.FileOp.CopyFile("/etc/docker/daemon.json", baseDir)
|
err = itemHelper.FileOp.CopyFile("/etc/docker/daemon.json", baseDir)
|
||||||
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", "/etc/docker/daemon.json"), err)
|
itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", "/etc/docker/daemon.json"), err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error {
|
||||||
newBackup.Credential = string(itemCredential)
|
newBackup.Credential = string(itemCredential)
|
||||||
|
|
||||||
if newBackup.Type == constant.OneDrive || newBackup.Type == constant.GoogleDrive {
|
if newBackup.Type == constant.OneDrive || newBackup.Type == constant.GoogleDrive {
|
||||||
if err := u.loadRefreshTokenByCode(&backup); err != nil {
|
if err := u.loadRefreshTokenByCode(&newBackup); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/core/constant"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -12,6 +11,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/core/constant"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -85,7 +86,7 @@ func NewWriterFromConfig(c *Config) (RollingWriter, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
filepath := FilePath(c)
|
filepath := FilePath(c)
|
||||||
file, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE|os.O_APPEND, constant.DirPerm)
|
file, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE|os.O_APPEND, constant.FilePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@
|
||||||
<PortJumpDialog ref="dialogPortJumpRef" />
|
<PortJumpDialog ref="dialogPortJumpRef" />
|
||||||
<BindDomain ref="bindDomainRef" />
|
<BindDomain ref="bindDomainRef" />
|
||||||
|
|
||||||
<TaskLog ref="taskLogRef" width="70%" />
|
<TaskLog ref="taskLogRef" width="70%" @close="search" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -570,8 +570,10 @@ const changeType = async () => {
|
||||||
switch (dialogData.value.rowData!.type) {
|
switch (dialogData.value.rowData!.type) {
|
||||||
case 'COS':
|
case 'COS':
|
||||||
case 'OSS':
|
case 'OSS':
|
||||||
case 'S3':
|
|
||||||
dialogData.value.rowData.varsJson['scType'] = 'Standard';
|
dialogData.value.rowData.varsJson['scType'] = 'Standard';
|
||||||
|
break;
|
||||||
|
case 'S3':
|
||||||
|
dialogData.value.rowData.varsJson['scType'] = 'STANDARD';
|
||||||
dialogData.value.rowData.varsJson['mode'] = 'virtual hosted';
|
dialogData.value.rowData.varsJson['mode'] = 'virtual hosted';
|
||||||
break;
|
break;
|
||||||
case 'KODO':
|
case 'KODO':
|
||||||
|
|
|
||||||
|
|
@ -641,6 +641,7 @@ function load18n(label: string) {
|
||||||
case 'Container':
|
case 'Container':
|
||||||
case 'App':
|
case 'App':
|
||||||
case 'System':
|
case 'System':
|
||||||
|
case 'Website':
|
||||||
return i18n.global.t('menu.' + label.toLowerCase());
|
return i18n.global.t('menu.' + label.toLowerCase());
|
||||||
case 'RuntimeExtension':
|
case 'RuntimeExtension':
|
||||||
return i18n.global.t('website.runtime');
|
return i18n.global.t('website.runtime');
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue