Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion internal/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (fh *FileHandle) WriteFile(offset int64, data []byte) (err error) {
return fh.lastWriteError
}

if offset != fh.nextWriteOffset {
if offset < fh.nextWriteOffset {
fh.inode.errFuse("WriteFile: only sequential writes supported", fh.nextWriteOffset, offset)
fh.lastWriteError = syscall.ENOTSUP
return fh.lastWriteError
Expand All @@ -230,6 +230,37 @@ func (fh *FileHandle) WriteFile(offset int64, data []byte) (err error) {
fh.dirty = true
}

// fill the hole with zero
if offset > fh.nextWriteOffset {
toSkip := offset - fh.nextWriteOffset
n := 10240
data := make([]byte, n)

for {
if fh.buf == nil {
fh.buf = MBuf{}.Init(fh.poolHandle, fh.partSize(), true)
}

if toSkip < int64(n) {
n = int(toSkip)
}
nCopied, _ := fh.buf.Write(data[:n])
toSkip -= int64(nCopied)
fh.nextWriteOffset += int64(nCopied)

if fh.buf.Full() {
err = fh.uploadCurrentBuf(!fh.cloud.Capabilities().NoParallelMultipart)
if err != nil {
return
}
}

if toSkip == 0 {
break
}
}
}

for {
if fh.buf == nil {
fh.buf = MBuf{}.Init(fh.poolHandle, fh.partSize(), true)
Expand Down