com.lunatech.cmt.admin.TargetFolderValidation.scala Maven / Gradle / Ivy
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