From 21c117bcfc9eddd8f8f5e8505d7022306f01cd2f Mon Sep 17 00:00:00 2001 From: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:53:34 +0100 Subject: [PATCH] Handling the case when the 'modules' or 'examples' directory is actually a file Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com> --- backend/internal/moduleindex/generator.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/internal/moduleindex/generator.go b/backend/internal/moduleindex/generator.go index 19cd822..0a55f64 100644 --- a/backend/internal/moduleindex/generator.go +++ b/backend/internal/moduleindex/generator.go @@ -594,6 +594,11 @@ func (g generator) extractSubmodules(ctx context.Context, addr ModuleAddr, ver M // that the submodule exists. However, we do not index the contents of the submodule. const directoryPrefix = "modules" + // Check if the modules directory is actually a file. + if _, err := workingCopy.Open(directoryPrefix); err == nil { + // This is a file, ignore it. + return nil + } entries, err := workingCopy.ReadDir(directoryPrefix) if err != nil { if os.IsNotExist(err) { @@ -643,6 +648,11 @@ func (g generator) extractExamples(ctx context.Context, moduleAddr ModuleAddr, v // Note: we extract the fact that an example exists even if the license is not OK because we just index the fact // that the submodule exists. However, we do not index the contents of the submodule. const directoryPrefix = "examples" + // Check if the examples directory is actually a file. + if _, err := workingCopy.Open(directoryPrefix); err == nil { + // This is a file, ignore it. + return nil + } entries, err := workingCopy.ReadDir(directoryPrefix) if err != nil { if os.IsNotExist(err) {