-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra target folder validation on cmta commands
- `cmta linearize` was missing target folder validation altogether - Added target folder validation on `cmta studentify` and `cmta linearize` commands
- Loading branch information
Showing
3 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
cmta/src/main/scala/com/lunatech/cmt/admin/TargetFolderValidation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.lunatech.cmt.admin | ||
|
||
import com.lunatech.cmt.CmtError | ||
import java.io.File | ||
import com.lunatech.cmt.toExecuteCommandErrorMessage | ||
|
||
def validateTargetFolder(mainRepository: File, target: File): Either[CmtError, Unit] = | ||
val canonicalStudentifyBaseDirectory = target.getCanonicalPath | ||
val canonicalMainRepository = mainRepository.getCanonicalPath | ||
val mainRepositoryEqualsStudentifyBaseDirectory = canonicalStudentifyBaseDirectory == canonicalMainRepository | ||
val StudentifyBaseDirectoryIsSubfolderOfmainRepository = | ||
canonicalStudentifyBaseDirectory.startsWith(canonicalMainRepository) | ||
(mainRepositoryEqualsStudentifyBaseDirectory, StudentifyBaseDirectoryIsSubfolderOfmainRepository) 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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters