mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
Discard OOM drafts written by previous app versions
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/experimental/libbox"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
@@ -60,6 +61,7 @@ func prepareWorkingDirectory() error {
|
||||
WorkingPath: workingDirectory,
|
||||
TempPath: workingDirectory,
|
||||
CrashReportSource: "Daemon",
|
||||
AppVersion: C.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/daemon"
|
||||
"github.com/sagernet/sing-box/experimental/libbox"
|
||||
"github.com/sagernet/sing-box/include"
|
||||
@@ -194,6 +195,7 @@ func (d *Daemon) configureWorkingDirectoryLocked(directory string) error {
|
||||
WorkingPath: directory,
|
||||
TempPath: directory,
|
||||
CrashReportSource: "Daemon",
|
||||
AppVersion: C.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -357,6 +357,17 @@ func promoteOOMDraftAt(workingPath string) {
|
||||
if err != nil || !info.IsDir() {
|
||||
return
|
||||
}
|
||||
metadataContent, err := os.ReadFile(filepath.Join(draftPath, "metadata.json"))
|
||||
if err != nil {
|
||||
os.RemoveAll(draftPath)
|
||||
return
|
||||
}
|
||||
var draftMetadata reportMetadata
|
||||
err = json.Unmarshal(metadataContent, &draftMetadata)
|
||||
if err != nil || draftMetadata.AppVersion != sAppVersion || draftMetadata.AppMarketingVersion != sAppMarketingVersion {
|
||||
os.RemoveAll(draftPath)
|
||||
return
|
||||
}
|
||||
reportsDir := filepath.Join(workingPath, "oom_reports")
|
||||
initReportDir(reportsDir)
|
||||
destPath, err := nextAvailableReportPath(reportsDir, info.ModTime().UTC())
|
||||
|
||||
@@ -34,11 +34,13 @@ func baseReportMetadata() reportMetadata {
|
||||
processName = ""
|
||||
}
|
||||
return reportMetadata{
|
||||
Source: sCrashReportSource,
|
||||
ProcessName: processName,
|
||||
ProcessPath: processPath,
|
||||
CoreVersion: C.Version,
|
||||
GoVersion: GoVersion(),
|
||||
Source: sCrashReportSource,
|
||||
ProcessName: processName,
|
||||
ProcessPath: processPath,
|
||||
AppVersion: sAppVersion,
|
||||
AppMarketingVersion: sAppMarketingVersion,
|
||||
CoreVersion: C.Version,
|
||||
GoVersion: GoVersion(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ var (
|
||||
sLogMaxLines int
|
||||
sDebug bool
|
||||
sCrashReportSource string
|
||||
sAppVersion string
|
||||
sAppMarketingVersion string
|
||||
sOOMKillerEnabled bool
|
||||
sOOMKillerDisabled bool
|
||||
sOOMMemoryLimit int64
|
||||
@@ -52,6 +54,8 @@ type SetupOptions struct {
|
||||
LogMaxLines int
|
||||
Debug bool
|
||||
CrashReportSource string
|
||||
AppVersion string
|
||||
AppMarketingVersion string
|
||||
OomKillerEnabled bool
|
||||
OomKillerDisabled bool
|
||||
OomMemoryLimit int64
|
||||
@@ -75,6 +79,8 @@ func applySetupOptions(options *SetupOptions) {
|
||||
sLogMaxLines = options.LogMaxLines
|
||||
sDebug = options.Debug
|
||||
sCrashReportSource = options.CrashReportSource
|
||||
sAppVersion = options.AppVersion
|
||||
sAppMarketingVersion = options.AppMarketingVersion
|
||||
ReloadSetupOptions(options)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user