Skip to content

Commit

Permalink
Project Manager fails to create directory when one exists (#11804)
Browse files Browse the repository at this point in the history
close #11758

Changelog:
- update: FileSystemService fails to create directory if one exists
  • Loading branch information
4e6 authored Dec 9, 2024
1 parent 106e112 commit 485840f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 485840f

Please sign in to comment.