fix: linear

This commit is contained in:
崔竞宁
2022-12-08 23:38:37 +08:00
parent 9fde45f6fd
commit 7d4accc441
3 changed files with 28 additions and 3 deletions

23
job.go
View File

@@ -126,9 +126,30 @@ type writeJob struct {
ch chan struct{}
}
func newWriteJob(job *baseJob, src *mmap.ReaderAt, needWait bool) *writeJob {
j := &writeJob{
baseJob: job,
src: src,
}
if needWait {
j.ch = make(chan struct{})
}
return j
}
func (wj *writeJob) done() {
wj.src.Close()
close(wj.ch)
if wj.ch != nil {
close(wj.ch)
}
}
func (wj *writeJob) wait() {
if wj.ch == nil {
return
}
<-wj.ch
}
type Job struct {

4
opt.go
View File

@@ -91,6 +91,10 @@ func (o *option) check() error {
o.fromDevice.check()
o.toDevice.check()
if o.fromDevice.linear || o.toDevice.linear {
o.fromDevice.threads = 1
o.toDevice.threads = 1
}
if o.logger == nil {
o.logger = logrus.StandardLogger()
}

View File

@@ -45,9 +45,9 @@ func (c *Copyer) prepare(ctx context.Context, indexed <-chan *baseJob) <-chan *w
return
}
wj := &writeJob{baseJob: job, src: file, ch: make(chan struct{})}
wj := newWriteJob(job, file, c.fromDevice.linear)
ch <- wj
<-wj.ch
wj.wait()
}
}
})