private void processFileChange()

in src/org/jetbrains/tfsIntegration/core/tfs/operations/ApplyGetOperations.java [285:376]


  private void processFileChange(final GetOperation operation) throws TfsException {
    File source = VersionControlPath.getFile(operation.getSlocal());
    File target = VersionControlPath.getFile(operation.getTlocal());
    final ChangeTypeMask change = new ChangeTypeMask(operation.getChg());

    if (source.equals(target) &&
        operation.getLver() == operation.getSver() &&
        (change.containsOnly(ChangeType_type0.Rename) ||
         (myDownloadMode != DownloadMode.FORCE && myDownloadMode != DownloadMode.MERGE))) {
      // rename + source=target means rename of parent folder
      // not an explicit change, nothing to do
      updateLocalVersion(operation);
      return;
    }

    if (!source.equals(target) && source.canWrite()) {
      if (canOverrideLocalConflictingItem(operation, true)) {
        if (myDownloadMode == DownloadMode.FORCE && !deleteFile(source)) {
          return;
        }
      }
      else {
        return;
      }
    }

    if (!source.equals(target) && source.isDirectory() && (!canOverrideLocalConflictingItem(operation, true) || !deleteFile(source))) {
      return;
    }

    if (target.isDirectory()) {
      // Note: TFC does not report local conflict in this case
      String errorMessage = MessageFormat.format("Cannot create file ''{0}'' because there is a folder with same name", target.getPath());
      myErrors.add(new VcsException(errorMessage));
      return;
    }

    // don't ask 2nd time if source = target
    if (target.canWrite() && !target.equals(source) && !canOverrideLocalConflictingItem(operation, false)) {
      return;
    }

    if (!createFolder(target.getParentFile())) {
      return;
    }

    if (myDownloadMode == DownloadMode.FORCE || (myDownloadMode != DownloadMode.MERGE && operation.getLver() != operation.getSver())) {
      // remove source, create target
      // don't download file if undoing Add
      if ((source.equals(target) || deleteFile(source)) && (change.contains(ChangeType_type0.Add) || downloadFile(operation))) {
        updateLocalVersion(operation);
        if (source.equals(target)) {
          addToGroup(FileGroup.UPDATED_ID, target, operation);
        }
        else {
          addToGroup(FileGroup.REMOVED_FROM_REPOSITORY_ID, source, operation);
          addToGroup(FileGroup.CREATED_ID, target, operation);
        }
      }
      return;
    }

    if (!target.exists()) {
      if (source.exists()) {
        // source exists (so it is a file), target is not
        if (rename(source, target)) {
          addToGroup(FileGroup.UPDATED_ID, target, operation);
          updateLocalVersion(operation);
        }
      }
      else {
        // source & target not exist
        // don't create file if undoing locally missing scheduled for addition file
        if (!change.contains(ChangeType_type0.Add) || !source.equals(target) || operation.getLver() != operation.getSver()) {
          if (downloadFile(operation)) {
            addToGroup(FileGroup.CREATED_ID, target, operation);
            updateLocalVersion(operation);
          }
        }
      }
    }
    else {
      // target exists
      if (!source.equals(target)) {
        deleteFile(source);
      }
      if (myDownloadMode == DownloadMode.MERGE) {
        addToGroup(FileGroup.MERGED_ID, target, operation);
      }
      updateLocalVersion(operation);
    }
  }