private async Task ProcessFileCollision()

in Core/src/Impl/Commands/UploadCommand.cs [188:213]


    private async Task<bool> ProcessFileCollision(ILogger logger, IStorage dstStorage, IStorage? backupStorage, SymbolStoragePath srcFile, SymbolStoragePath dstFile)
    {
      var resolutionMode = srcFile.IsPeFileWithWeakHash() ? myPeCollisionResolutionMode : myCollisionResolutionMode;
      switch (resolutionMode)
      {
        case CollisionResolutionMode.Terminate:
          logger.Error($"The source file {srcFile} differs from the destination. Processing will be terminated.");
          return false;
        case CollisionResolutionMode.KeepExisted:
          logger.Fix($"The source file {srcFile} differs from the destination. Preserve existed file.");
          return false;
        case CollisionResolutionMode.Overwrite when backupStorage != null:
          logger.Fix($"The source file {srcFile} differs from the destination. File will be overwritten, backup will be created.");
          // Assume that there is no collisions most of the time and for rare circumstances it is ok to re-read file from destination storage
          await dstStorage.OpenForReadingAsync(dstFile, async stream => { await backupStorage.CreateForWritingAsync(dstFile, AccessMode.Public, stream); });
          // Storage overwrites existed files, so this will work as expected
          return true;
        case CollisionResolutionMode.Overwrite when backupStorage == null:
        case CollisionResolutionMode.OverwriteWithoutBackup:
          logger.Fix($"The source file {srcFile} differs from the destination. File will be overwritten without backup.");
          // Storage overwrites existed files, so this will work as expected
          return true;
        default:
          throw new InvalidOperationException("Unknown CollisionResolutionMode value: " + resolutionMode);
      }
    }