MCPcopy Index your code
hub / github.com/rclone/rclone / writeAt

Method writeAt

vfs/write.go:128–155  ·  view source on GitHub ↗

Implementation of WriteAt - call with lock held

(p []byte, off int64)

Source from the content-addressed store, hash-verified

126
127// Implementation of WriteAt - call with lock held
128func (fh *WriteFileHandle) writeAt(p []byte, off int64) (n int, err error) {
129 // defer log.Trace(fh.remote, "len=%d off=%d", len(p), off)("n=%d, fh.off=%d, err=%v", &n, &fh.offset, &err)
130 if fh.closed {
131 fs.Errorf(fh.remote, "WriteFileHandle.Write: error: %v", EBADF)
132 return 0, ECLOSED
133 }
134 if fh.offset != off {
135 waitSequential("write", fh.remote, &fh.cond, time.Duration(fh.file.VFS().Opt.WriteWait), &fh.offset, off)
136 }
137 if fh.offset != off {
138 fs.Errorf(fh.remote, "WriteFileHandle.Write: can't seek in file without --vfs-cache-mode >= writes")
139 return 0, ESPIPE
140 }
141 if err = fh.openPending(); err != nil {
142 return 0, err
143 }
144 fh.writeCalled = true
145 n, err = fh.pipeWriter.Write(p)
146 fh.offset += int64(n)
147 fh.file.setSize(fh.offset)
148 if err != nil {
149 fs.Errorf(fh.remote, "WriteFileHandle.Write error: %v", err)
150 return 0, err
151 }
152 // fs.Debugf(fh.remote, "WriteFileHandle.Write OK (%d bytes written)", n)
153 fh.cond.Broadcast() // wake everyone up waiting for an in-sequence read
154 return n, nil
155}
156
157// Write writes len(p) bytes from p to the underlying data stream. It returns
158// the number of bytes written from p (0 <= n <= len(p)) and any error

Callers 3

WriteAtMethod · 0.95
WriteMethod · 0.95
FlushMethod · 0.95

Calls 6

openPendingMethod · 0.95
ErrorfFunction · 0.92
waitSequentialFunction · 0.85
setSizeMethod · 0.80
VFSMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected