fn flush()

in src/fs.rs [667:729]


    fn flush(
        &mut self,
        _req: &Request<'_>,
        inode: u64,
        fh: u64,
        _lock_owner: u64,
        reply: ReplyEmpty,
    ) {
        debug!("flush called for inode {} / fh {}", inode, fh);
        if fh == 0 {
            // Ignore fh 0
            reply.ok();
            return;
        }

        let now = SystemTime::now();

        let fh_clone = fh;
        let mut fh_map = self.file_handles.write().unwrap();
        let cursor_or_none = fh_map.get_mut(&fh_clone);

        if cursor_or_none.is_none() {
            error!("flush(): didn't find the fh {}", fh);
            reply.error(libc::EBADF);
            return;
        }

        let inode_clone = inode;
        let mut attr_map = self.inode_to_attr.write().unwrap();
        let attr_or_none = attr_map.get_mut(&inode_clone);
        if attr_or_none.is_none() {
            error!("flush(): Didn't find inode {}", inode);
            reply.error(libc::EBADF);
            return;
        }

        let cursor = cursor_or_none.unwrap();
        let result = self.tokio_rt.block_on(async {
            super::gcs::finalize_upload_with_client(&self.gcs_client, cursor).await
        });

        if result.is_err() {
            error!("finalze upload failed with err {:#?}", result);
            reply.error(libc::EIO);
            return;
        }

        // We've got an Object now! Update our FileAttr and map.
        let obj: Object = result.unwrap();
        debug!("Got back our object! {:#?}", obj);

        let mut attr = attr_or_none.unwrap();
        // Update our atime/mtime.
        attr.atime = now;
        attr.mtime = now;
        // Finalize the object size.
        attr.size = obj.size;

        // Put the Object into our map (allownig reads!).
        self.inode_to_obj.write().unwrap().insert(inode, obj);

        reply.ok();
    }