mirror of
https://github.com/enso-org/enso.git
synced 2024-09-11 13:15:52 +03:00
Fix project manager projects loading (#1145)
Fix loading of Enso projects in the enso/projects directory
This commit is contained in:
parent
2155fa8e88
commit
9666d9065e
@ -60,11 +60,12 @@ class ProjectFileRepository[
|
||||
override def getAll(): F[ProjectRepositoryFailure, List[Project]] =
|
||||
fileSystem
|
||||
.list(storageConfig.userProjectsPath)
|
||||
.map(_.filter(_.isDirectory))
|
||||
.recover {
|
||||
case FileNotFound | NotDirectory => Nil
|
||||
}
|
||||
.mapError(th => StorageFailure(th.toString))
|
||||
.flatMap(s => Traverse[List].traverse(s)(loadProject).map(_.flatten))
|
||||
.flatMap(s => Traverse[List].traverse(s)(tryLoadProject).map(_.flatten))
|
||||
|
||||
/** @inheritdoc */
|
||||
override def findById(
|
||||
@ -84,15 +85,18 @@ class ProjectFileRepository[
|
||||
.mapError(th => StorageFailure(th.toString))
|
||||
} yield ()
|
||||
|
||||
private def loadProject(
|
||||
private def tryLoadProject(
|
||||
directory: File
|
||||
): F[ProjectRepositoryFailure, Option[Project]] =
|
||||
): F[ProjectRepositoryFailure, Option[Project]] = {
|
||||
val noop: F[ProjectRepositoryFailure, Option[ProjectMetadata]] =
|
||||
Applicative[F].pure(None)
|
||||
for {
|
||||
pkgOpt <- loadPackage(directory)
|
||||
meta <- metadataStorage(directory)
|
||||
.load()
|
||||
.mapError(_.fold(convertFileStorageFailure))
|
||||
} yield pkgOpt.map { pkg =>
|
||||
pkgOpt <- loadPackage(directory)
|
||||
metaOpt <- pkgOpt.fold(noop)(_ => loadMetadata(directory))
|
||||
} yield for {
|
||||
pkg <- pkgOpt
|
||||
meta <- metaOpt
|
||||
} yield {
|
||||
Project(
|
||||
id = meta.id,
|
||||
name = pkg.name,
|
||||
@ -102,6 +106,15 @@ class ProjectFileRepository[
|
||||
path = Some(directory.toString)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private def loadMetadata(
|
||||
directory: File
|
||||
): F[ProjectRepositoryFailure, Option[ProjectMetadata]] =
|
||||
metadataStorage(directory)
|
||||
.load()
|
||||
.map(Some(_))
|
||||
.mapError(_.fold(convertFileStorageFailure))
|
||||
|
||||
private def createProjectStructure(
|
||||
project: Project,
|
||||
|
Loading…
Reference in New Issue
Block a user