code: func (fm *filesManager) truncateFile(file *file, offset int64) error {
  	reopen := false
  	fd := file.handle
  	if file.flags&os.O_APPEND != 0 {
  		if err := fm.closeLockedFile(file); err != nil {
  			return err
  		}
  		var err error
  		fd, err = openFileWithFlags(file.name, os.O_RDWR)
  		if err != nil {
  			return err
  		}
  		reopen = true
  	}
  	newPos := offset
  	if err := fd.Truncate(newPos); err != nil {
  		return err
  	}
  	pos, err := fd.Seek(newPos, io.SeekStart) // or Seek(0, io.SeekEnd)
  	if err != nil {
  		return err
  	}
  	if pos != newPos {
  		return fmt.Errorf("unable to set position of file %q to %v", file.name, newPos)
  	}
  	if reopen {
  		if err := fd.Close(); err != nil {
  			return err
  		}
  		if err := fm.openFile(file); err != nil {
  			return err
  		}
  	}
  	return nil
  }
docs: // truncateFile truncates the file to the given offset.
  // The file is assumed to be locked on entry.
  // If the file's flags indicate that this file is opened with O_APPEND, it
  // is first closed, reopened in non append mode, truncated, then reopened
  // (and locked) with original flags.