Flush is called on each close() of a file descriptor. So if a filesystem wants to return write errors in close() and the file has cached dirty data, this is a good place to write back data and return any errors. Since many applications ignore close() errors this is not always useful. NOTE: The flus
()
| 235 | // Filesystems shouldn't assume that flush will always be called after |
| 236 | // some writes, or that if will be called at all. |
| 237 | func (fh *WriteFileHandle) Flush() error { |
| 238 | fh.mu.Lock() |
| 239 | defer fh.mu.Unlock() |
| 240 | if fh.closed { |
| 241 | fs.Debugf(fh.remote, "WriteFileHandle.Flush nothing to do") |
| 242 | return nil |
| 243 | } |
| 244 | // fs.Debugf(fh.remote, "WriteFileHandle.Flush") |
| 245 | // If Write hasn't been called then ignore the Flush - Release |
| 246 | // will pick it up |
| 247 | if !fh.writeCalled { |
| 248 | fs.Debugf(fh.remote, "WriteFileHandle.Flush unwritten handle, writing 0 bytes to avoid race conditions") |
| 249 | _, err := fh.writeAt([]byte{}, fh.offset) |
| 250 | return err |
| 251 | } |
| 252 | err := fh.close() |
| 253 | if err != nil { |
| 254 | fs.Errorf(fh.remote, "WriteFileHandle.Flush error: %v", err) |
| 255 | //} else { |
| 256 | // fs.Debugf(fh.remote, "WriteFileHandle.Flush OK") |
| 257 | } |
| 258 | return err |
| 259 | } |
| 260 | |
| 261 | // Release is called when we are finished with the file handle |
| 262 | // |