All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lunatech.cmt.admin.TargetFolderValidation.scala Maven / Gradle / Ivy

There is a newer version: 2.0.19
Show newest version
package com.lunatech.cmt.admin

import com.lunatech.cmt.CmtError
import java.io.File
import com.lunatech.cmt.toExecuteCommandErrorMessage

def validateDestinationFolder(mainRepository: File, destination: File): Either[CmtError, Unit] =
  val canonicalTarget = destination.getCanonicalPath
  val canonicalMainRepository = mainRepository.getCanonicalPath
  val destinationEqualsMainRepository = canonicalTarget == canonicalMainRepository
  val destinationIsSubfolderOfmainRepository =
    canonicalTarget.startsWith(canonicalMainRepository)
  (destinationEqualsMainRepository, destinationIsSubfolderOfmainRepository) match {
    case (true, _) =>
      Left("destination folder cannot be the same as the main repository root folder".toExecuteCommandErrorMessage)
    case (_, true) =>
      Left("destination folder cannot be a subfolder of the main repository".toExecuteCommandErrorMessage)
    case _ =>
      Right(())
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy