private void saveFsState(File dataStorageRoot, BuildFSState state) {
    final ProjectDescriptor pd = myProjectDescriptor;
    final File file = new File(dataStorageRoot, FS_STATE_FILE);
    try {
      final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
      final DataOutputStream out = new DataOutputStream(bytes);
      try {
        out.writeInt(FSState.VERSION);
        out.writeLong(myLastEventOrdinal);
        boolean hasWorkToDoWithModules = false;
        for (JpsModule module : pd.getProject().getModules()) {
          for (JavaModuleBuildTargetType type : JavaModuleBuildTargetType.ALL_TYPES) {
            if (state.hasWorkToDo(new ModuleBuildTarget(module, type))) {
              hasWorkToDoWithModules = true;
              break;
            }
          }
          if (hasWorkToDoWithModules) {
            break;
          }
        }
        out.writeBoolean(hasWorkToDoWithModules);
        state.save(out);
      } finally {
        out.close();
      }

      saveOnDisk(bytes, file);
    } catch (Throwable e) {
      LOG.error(e);
      FileUtil.delete(file);
    }
  }