Project Manager fails to create directory when one exists (#11804)

close #11758

Changelog:
- update: FileSystemService fails to create directory if one exists
This commit is contained in:
Dmitry Bushev 2024-12-09 15:16:06 +03:00 committed by GitHub
parent 106e112cea
commit 485840fefd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -73,7 +73,10 @@ class BlockingFileSystem[F[+_, +_]: Sync: ErrorChannel](
/** @inheritdoc */
override def createDir(path: File): F[FileSystemFailure, Unit] =
Sync[F]
.blockingOp { FileUtils.forceMkdir(path) }
.blockingOp {
if (path.exists()) throw new FileExistsException()
FileUtils.forceMkdir(path)
}
.mapError(toFsFailure)
.timeoutFail(OperationTimeout)(ioTimeout)

View File

@ -110,6 +110,29 @@ class FileSystemServiceSpec
FileUtils.deleteQuietly(directoryPath)
}
"create directory fail when one exists with the same name" in {
val testDir = testStorageConfig.userProjectsPath
val directoryName = "filesystem_test_create_dir_with_same_name"
val directoryPath = new File(testDir, directoryName)
val result1 = fileSystemService
.createDirectory(directoryPath)
.unsafeRunSync()
result1 shouldEqual Right(())
Files.isDirectory(directoryPath.toPath) shouldEqual true
val result2 = fileSystemService
.createDirectory(directoryPath)
.unsafeRunSync()
result2.isLeft shouldEqual true
// cleanup
FileUtils.deleteQuietly(directoryPath)
}
"delete directory" in {
implicit val client: WsTestClient = new WsTestClient(address)