mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 00:52:09 +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]] =
|
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user