close the file handle returning EBADF if it has been closed already. Must be called with fh.mu held. Note that we leave the file around in the cache on error conditions to give the user a chance to recover it.
()
| 154 | // Note that we leave the file around in the cache on error conditions |
| 155 | // to give the user a chance to recover it. |
| 156 | func (fh *RWFileHandle) close() (err error) { |
| 157 | defer log.Trace(fh.logPrefix(), "")("err=%v", &err) |
| 158 | fh.file.muRW.Lock() |
| 159 | defer fh.file.muRW.Unlock() |
| 160 | |
| 161 | if fh.closed { |
| 162 | return ECLOSED |
| 163 | } |
| 164 | |
| 165 | fh.closed = true |
| 166 | fh.updateSize() |
| 167 | if fh.opened { |
| 168 | err = fh.item.Close(fh.file.setObject) |
| 169 | fh.opened = false |
| 170 | } else { |
| 171 | // apply any pending mod times if any |
| 172 | _ = fh.file.applyPendingModTime() |
| 173 | } |
| 174 | |
| 175 | if !fh.readOnly() { |
| 176 | fh.file.delWriter(fh) |
| 177 | } |
| 178 | |
| 179 | return err |
| 180 | } |
| 181 | |
| 182 | // Close closes the file |
| 183 | func (fh *RWFileHandle) Close() error { |