File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -3,17 +3,33 @@ package common
3
3
import (
4
4
"os"
5
5
"path/filepath"
6
+ "time"
6
7
7
8
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
8
9
)
9
10
10
11
var tempdir = ".temp"
11
12
12
13
func init () {
14
+ // 在opensca-cli所在目录下创建临时目录
13
15
excpath , _ := os .Executable ()
14
16
tempdir = filepath .Join (filepath .Dir (excpath ), tempdir )
15
- // os.RemoveAll(tempdir)
16
17
os .MkdirAll (tempdir , 0755 )
18
+ // 删除24小时前的临时文件(一般是进程意外中断时未被删除的临时文件)
19
+ old := time .Now ().Add (- 24 * time .Hour )
20
+ entries , err := os .ReadDir (tempdir )
21
+ if err != nil {
22
+ return
23
+ }
24
+ for _ , entry := range entries {
25
+ info , err := entry .Info ()
26
+ if err != nil {
27
+ continue
28
+ }
29
+ if info .ModTime ().Before (old ) {
30
+ os .RemoveAll (filepath .Join (tempdir , entry .Name ()))
31
+ }
32
+ }
17
33
}
18
34
19
35
func MkdirTemp (pattern string ) string {
You can’t perform that action at this time.
0 commit comments