Skip to content

Commit e60ecbe

Browse files
committed
修复report报告mac存在漏报问题 & version 1.3.1
1 parent 3eb95af commit e60ecbe

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

cmd/afrog/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func main() {
5555
r := result.(*core.Result)
5656

5757
lock.Lock()
58-
defer lock.Unlock()
5958

6059
if !options.Silent {
6160
options.CurrentCount++
@@ -77,6 +76,8 @@ func main() {
7776
fmt.Printf("\r%d/%d | %d%% ", options.CurrentCount, options.Count, options.CurrentCount*100/options.Count)
7877
}
7978

79+
lock.Unlock()
80+
8081
})
8182
if err != nil {
8283
return err

internal/runner/banner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func ShowBanner() string {
12-
return "afrog"
12+
return "afrog 五一劳动节版"
1313
}
1414

1515
func ShowUsage() string {

pkg/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Ceye struct {
3939
}
4040

4141
const afrogConfigFilename = "afrog-config.yaml"
42-
const Version = "1.3.0"
42+
const Version = "1.3.1"
4343

4444
// Create and initialize afrog-config.yaml configuration info
4545
func New() (*Config, error) {

pkg/html/html.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type HtmlTemplate struct {
1616
Result *core.Result
1717
Filename string
1818
Number string
19+
Syncfile *utils.Syncfile
1920
}
2021

2122
const outputDirectory = "./reports"
@@ -30,14 +31,18 @@ func (ht *HtmlTemplate) New() error {
3031
}
3132

3233
ouputFile := filepath.Join(outputDirectory, ht.Filename)
33-
// if utils.Exists(ouputFile) {
34-
// return errors.New("output filename had existed")
35-
// }
3634

3735
os.MkdirAll(outputDirectory, os.ModePerm)
3836
ht.Filename = ouputFile
3937

40-
return utils.WriteFile(ouputFile, []byte(header()))
38+
os.Remove(ht.Filename)
39+
40+
sf, err := utils.NewSyncfile(ht.Filename)
41+
if err != nil {
42+
return err
43+
}
44+
ht.Syncfile = sf
45+
sf.Write(header())
4146
}
4247
return nil
4348
}
@@ -124,12 +129,11 @@ func (ht *HtmlTemplate) Html() string {
124129
}
125130

126131
func (ht *HtmlTemplate) Append() {
127-
r := ht.Html()
128-
if len(r) > 0 {
129-
utils.AppendString(ht.Filename, r)
130-
// fmt.Println(err)
132+
content := ht.Html()
133+
if len(content) > 0 {
134+
// utils.AppendString(ht.Filename, r)
135+
ht.Syncfile.Write(content)
131136
}
132-
// fmt.Println(len(r))
133137
}
134138

135139
func header() string {

pkg/utils/syncfile.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package utils
2+
3+
import (
4+
"bufio"
5+
"os"
6+
"sync"
7+
)
8+
9+
type Syncfile struct {
10+
mutex *sync.Mutex
11+
iohandler *os.File
12+
}
13+
14+
func NewSyncfile(filename string) (*Syncfile, error) {
15+
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
16+
if err != nil {
17+
return nil, err
18+
}
19+
return &Syncfile{mutex: &sync.Mutex{}, iohandler: f}, nil
20+
}
21+
22+
func (sf *Syncfile) Write(content string) {
23+
sf.mutex.Lock()
24+
25+
wbuf := bufio.NewWriterSize(sf.iohandler, len(content))
26+
wbuf.WriteString(content)
27+
wbuf.Flush()
28+
29+
RandSleep(1)
30+
31+
sf.mutex.Unlock()
32+
}

0 commit comments

Comments
 (0)