code: func (fm *filesManager) close() error {
  	fm.Lock()
  	if fm.isClosed {
  		fm.Unlock()
  		return nil
  	}
  	fm.isClosed = true
  
  	files := make([]*file, 0, len(fm.files))
  	for _, file := range fm.files {
  		files = append(files, file)
  	}
  	fm.files = nil
  	fm.Unlock()
  
  	var err error
  	for _, file := range files {
  		wasOpened, sserr := fm.trySwitchState(file, fmClosed)
  		if sserr != nil {
  			if err == nil {
  				err = sserr
  			}
  		} else if wasOpened {
  			fm.Lock()
  			if cerr := fm.doClose(file); cerr != nil && err == nil {
  				err = cerr
  			}
  			fm.Unlock()
  		}
  	}
  	return err
  }
docs: // close the files manager, including all files currently opened.
  // Returns the first error encountered when closing the files.