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

Method openPending

vfs/write.go:61–87  ·  view source on GitHub ↗

openPending opens the file if there is a pending open call with the lock held

()

Source from the content-addressed store, hash-verified

59//
60// call with the lock held
61func (fh *WriteFileHandle) openPending() (err error) {
62 if fh.opened {
63 return nil
64 }
65 if !fh.safeToTruncate() {
66 fs.Errorf(fh.remote, "WriteFileHandle: Can't open for write without O_TRUNC on existing file without --vfs-cache-mode >= writes")
67 return EPERM
68 }
69 var pipeReader *io.PipeReader
70 pipeReader, fh.pipeWriter = io.Pipe()
71 go func() {
72 // NB Rcat deals with Stats.Transferring, etc.
73 o, err := operations.Rcat(fh.file.ctx, fh.file.Fs(), fh.remote, pipeReader, time.Now(), nil)
74 if err != nil {
75 fs.Errorf(fh.remote, "WriteFileHandle.New Rcat failed: %v", err)
76 }
77 // Close the pipeReader so the pipeWriter fails with ErrClosedPipe
78 _ = pipeReader.Close()
79 fh.o = o
80 fh.result <- err
81 }()
82 fh.file.setSize(0)
83 fh.truncated = true
84 fh.file.Dir().addObject(fh.file) // make sure the directory has this object in it now
85 fh.opened = true
86 return nil
87}
88
89// String converts it to printable
90func (fh *WriteFileHandle) String() string {

Callers 2

writeAtMethod · 0.95
closeMethod · 0.95

Calls 8

safeToTruncateMethod · 0.95
ErrorfFunction · 0.92
RcatFunction · 0.92
setSizeMethod · 0.80
addObjectMethod · 0.80
DirMethod · 0.80
FsMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected