Skip to content

Commit

Permalink
bugfix: Clean all temporary files before today
Browse files Browse the repository at this point in the history
  • Loading branch information
aooohan committed Jan 23, 2024
1 parent 5763ac1 commit c738772
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
func NewConfigWithPath(p string) (*Config, error) {
if !util.FileExists(p) {
content, err := yaml.Marshal(defaultConfig)
if err != nil {
if err == nil {
_ = os.WriteFile(p, content, 0644)
return defaultConfig, nil
}
Expand Down
24 changes: 23 additions & 1 deletion internal/tmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/version-fox/vfox/internal/util"
)
Expand All @@ -30,7 +32,27 @@ type Temp struct {
}

func (t *Temp) Remove() {
_ = os.RemoveAll(t.CurProcessPath)
dir, err := os.ReadDir(t.dirPath)
if err == nil {
_ = os.RemoveAll(t.CurProcessPath)
for _, file := range dir {
if !file.IsDir() {
continue
}
names := strings.SplitN(file.Name(), "-", 2)
if len(names) != 2 {
continue
}
timestamp := names[0]
i, err := strconv.ParseInt(timestamp, 10, 64)
if err != nil {
continue
}
if util.IsBeforeToday(i) {
_ = os.Remove(filepath.Join(t.dirPath, file.Name()))
}
}
}
}

func NewTemp(dirPath string, pid int) (*Temp, error) {
Expand Down

0 comments on commit c738772

Please sign in to comment.