Merge pull request #6207 from dhiltgen/sparse_win

Ensure sparse files on windows during download
This commit is contained in:
Daniel Hiltgen 2024-08-06 11:06:06 -07:00 committed by GitHub
commit a4fdd03c3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View file

@ -216,6 +216,9 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *regis
return err return err
} }
defer file.Close() defer file.Close()
if err := setSparse(file); err != nil {
return err
}
_ = file.Truncate(b.Total) _ = file.Truncate(b.Total)

9
server/sparse_common.go Normal file
View file

@ -0,0 +1,9 @@
//go:build !windows
package server
import "os"
func setSparse(file *os.File) error {
return nil
}

16
server/sparse_windows.go Normal file
View file

@ -0,0 +1,16 @@
package server
import (
"os"
"golang.org/x/sys/windows"
)
func setSparse(file *os.File) error {
return windows.DeviceIoControl(
windows.Handle(file.Fd()), windows.FSCTL_SET_SPARSE,
nil, 0,
nil, 0,
nil, nil,
)
}