Fix project manager projects loading (#1145)

Fix loading of Enso projects in the enso/projects directory
This commit is contained in:
Dmitry Bushev 2020-09-14 15:17:54 +03:00 committed by GitHub
parent 2155fa8e88
commit 9666d9065e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,11 +60,12 @@ class ProjectFileRepository[
override def getAll(): F[ProjectRepositoryFailure, List[Project]] = override def getAll(): F[ProjectRepositoryFailure, List[Project]] =
fileSystem fileSystem
.list(storageConfig.userProjectsPath) .list(storageConfig.userProjectsPath)
.map(_.filter(_.isDirectory))
.recover { .recover {
case FileNotFound | NotDirectory => Nil case FileNotFound | NotDirectory => Nil
} }
.mapError(th => StorageFailure(th.toString)) .mapError(th => StorageFailure(th.toString))
.flatMap(s => Traverse[List].traverse(s)(loadProject).map(_.flatten)) .flatMap(s => Traverse[List].traverse(s)(tryLoadProject).map(_.flatten))
/** @inheritdoc */ /** @inheritdoc */
override def findById( override def findById(
@ -84,15 +85,18 @@ class ProjectFileRepository[
.mapError(th => StorageFailure(th.toString)) .mapError(th => StorageFailure(th.toString))
} yield () } yield ()
private def loadProject( private def tryLoadProject(
directory: File directory: File
): F[ProjectRepositoryFailure, Option[Project]] = ): F[ProjectRepositoryFailure, Option[Project]] = {
val noop: F[ProjectRepositoryFailure, Option[ProjectMetadata]] =
Applicative[F].pure(None)
for { for {
pkgOpt <- loadPackage(directory) pkgOpt <- loadPackage(directory)
meta <- metadataStorage(directory) metaOpt <- pkgOpt.fold(noop)(_ => loadMetadata(directory))
.load() } yield for {
.mapError(_.fold(convertFileStorageFailure)) pkg <- pkgOpt
} yield pkgOpt.map { pkg => meta <- metaOpt
} yield {
Project( Project(
id = meta.id, id = meta.id,
name = pkg.name, name = pkg.name,
@ -102,6 +106,15 @@ class ProjectFileRepository[
path = Some(directory.toString) path = Some(directory.toString)
) )
} }
}
private def loadMetadata(
directory: File
): F[ProjectRepositoryFailure, Option[ProjectMetadata]] =
metadataStorage(directory)
.load()
.map(Some(_))
.mapError(_.fold(convertFileStorageFailure))
private def createProjectStructure( private def createProjectStructure(
project: Project, project: Project,