openPending opens the file if there is a pending open call with the lock held
()
| 59 | // |
| 60 | // call with the lock held |
| 61 | func (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 |
| 90 | func (fh *WriteFileHandle) String() string { |