Handle sparse files (fixes #245)

This commit is contained in:
Jakob Borg
2015-11-21 16:30:53 +01:00
parent f7ad97918a
commit d46f267663
6 changed files with 136 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ type sharedPullerState struct {
reused int // Number of blocks reused from temporary file
ignorePerms bool
version protocol.Vector // The current (old) version
sparse bool
// Mutable, must be locked for access
err error // The first error we hit
@@ -138,6 +139,15 @@ func (s *sharedPullerState) tempFile() (io.WriterAt, error) {
return nil, err
}
if s.sparse {
// Truncate sets the size of the file. This creates a sparse file or a
// space reservation, depending on the underlying filesystem.
if err := fd.Truncate(s.file.Size()); err != nil {
s.failLocked("dst truncate", err)
return nil, err
}
}
// Same fd will be used by all writers
s.fd = fd