containerd / continuity

A transport-agnostic, filesystem metadata manifest system
https://containerd.io
Apache License 2.0
137 stars 66 forks source link

fs: use io.Copy because go supports CopyFileRange #227

Closed fuweid closed 1 year ago

fuweid commented 1 year ago

REF: https://github.com/golang/go/commit/7be3f09deb2dc1d57cfc18b18e12192be3544794

dmcgowan commented 1 year ago

I wonder if we could just get rid of this function all together, for unix we still do

func copyFileContent(dst, src *os.File) error {
    buf := bufferPool.Get().(*[]byte)
    _, err := io.CopyBuffer(dst, src, *buf)
    bufferPool.Put(buf)

    return err
}

Based on the Go code though, this buffer will never be used for os.File to os.File copying though https://github.com/golang/go/blob/master/src/os/file.go#L161

fuweid commented 1 year ago

I wonder if we could just get rid of this function all together

If the go runtime move the ReadFrom into linux platform, I guess it will be possible.

Updated. Please take a look.