@@ -11,6 +11,7 @@ import (
11
11
"os"
12
12
"path"
13
13
"slices"
14
+ "strings"
14
15
"sync"
15
16
"text/template"
16
17
"time"
@@ -348,7 +349,12 @@ func (g generator) generate(ctx context.Context, moduleList []module.Addr, block
348
349
}
349
350
for _ , m := range modules .Modules {
350
351
if err := m .Validate (); err != nil {
351
- return fmt .Errorf ("invalid module (%w)" , err )
352
+ // We are ignoring invalid version numbers here because the dataset contains them, but when a module is
353
+ // refreshed, it should be excluded above.
354
+ var invalidVersionNumber * module.InvalidVersionNumber
355
+ if ! errors .As (err , & invalidVersionNumber ) {
356
+ return fmt .Errorf ("invalid module (%w)" , err )
357
+ }
352
358
}
353
359
}
354
360
marshalled , err := json .Marshal (modules )
@@ -433,7 +439,7 @@ func (g generator) generateModuleVersion(ctx context.Context, moduleAddr ModuleA
433
439
}
434
440
435
441
g .log .Info (ctx , "Updating module details for %s version %s..." , moduleAddr , ver .ID )
436
- if err := g .refreshModuleDetails (ctx , moduleAddr , ver , & result .Details , workingCopy , licenseOK , entry .IsBlocked , entry .BlockedReason , "" ); err != nil {
442
+ if err := g .refreshModuleDetails (ctx , moduleAddr , ver , & result .Details , workingCopy , licenseOK , entry .IsBlocked , entry .BlockedReason , "" , "" ); err != nil {
437
443
return fmt .Errorf ("failed to extract module defaults for %s version %s (%w)" , moduleAddr , ver .ID , err )
438
444
}
439
445
@@ -471,9 +477,9 @@ func (g generator) refreshLicense(ctx context.Context, moduleAddr ModuleAddr, mo
471
477
return err
472
478
}
473
479
474
- func (g generator ) refreshModuleDetails (ctx context.Context , moduleAddr ModuleAddr , ver ModuleVersionDescriptor , d * Details , workingCopy vcs.WorkingCopy , licenseOK bool , blocked bool , blockedReason string , prefix string ) error {
480
+ func (g generator ) refreshModuleDetails (ctx context.Context , moduleAddr ModuleAddr , ver ModuleVersionDescriptor , d * Details , workingCopy vcs.WorkingCopy , licenseOK bool , blocked bool , blockedReason string , sourcePrefix string , dstPrefix string ) error {
475
481
var err error
476
- if d .Readme , d .EditLink , err = g .extractReadme (ctx , moduleAddr , ver , workingCopy , licenseOK , blocked , blockedReason , prefix ); err != nil {
482
+ if d .Readme , d .EditLink , err = g .extractReadme (ctx , moduleAddr , ver , workingCopy , licenseOK , blocked , blockedReason , sourcePrefix , dstPrefix ); err != nil {
477
483
return err
478
484
}
479
485
@@ -484,17 +490,17 @@ func (g generator) refreshModuleDetails(ctx context.Context, moduleAddr ModuleAd
484
490
return nil
485
491
}
486
492
487
- dir := path .Join (rawDirectory , prefix )
493
+ dir := path .Join (rawDirectory , sourcePrefix )
488
494
if err := g .extractModuleSchema (ctx , dir , d , licenseOK , blocked ); err != nil {
489
495
return err
490
496
}
491
497
492
498
return nil
493
499
}
494
500
495
- func (g generator ) refreshExampleDetails (ctx context.Context , moduleAddr ModuleAddr , ver ModuleVersionDescriptor , e * Example , workingCopy vcs.WorkingCopy , licenseOK bool , blocked bool , blockedReason string , prefix string ) error {
501
+ func (g generator ) refreshExampleDetails (ctx context.Context , moduleAddr ModuleAddr , ver ModuleVersionDescriptor , e * Example , workingCopy vcs.WorkingCopy , licenseOK bool , blocked bool , blockedReason string , sourcePrefix string , dstPrefix string ) error {
496
502
var err error
497
- if e .Readme , e .EditLink , err = g .extractReadme (ctx , moduleAddr , ver , workingCopy , licenseOK , blocked , blockedReason , prefix ); err != nil {
503
+ if e .Readme , e .EditLink , err = g .extractReadme (ctx , moduleAddr , ver , workingCopy , licenseOK , blocked , blockedReason , sourcePrefix , dstPrefix ); err != nil {
498
504
return err
499
505
}
500
506
@@ -505,18 +511,18 @@ func (g generator) refreshExampleDetails(ctx context.Context, moduleAddr ModuleA
505
511
return nil
506
512
}
507
513
508
- dir := path .Join (rawDirectory , prefix )
514
+ dir := path .Join (rawDirectory , sourcePrefix )
509
515
if err := g .extractExampleSchema (ctx , dir , e , licenseOK , blocked ); err != nil {
510
516
return err
511
517
}
512
518
513
519
return nil
514
520
}
515
521
516
- func (g generator ) extractReadme (ctx context.Context , moduleAddr ModuleAddr , ver ModuleVersionDescriptor , workingCopy vcs.WorkingCopy , licenseOK bool , blocked bool , blockedReason string , prefix string ) (bool , string , error ) {
522
+ func (g generator ) extractReadme (ctx context.Context , moduleAddr ModuleAddr , ver ModuleVersionDescriptor , workingCopy vcs.WorkingCopy , licenseOK bool , blocked bool , blockedReason string , sourcePrefix string , dstPrefix string ) (bool , string , error ) {
517
523
hasReadme := false
518
524
var readme []byte
519
- sourcePath := path .Join (prefix , "README.md" )
525
+ sourcePath := path .Join (sourcePrefix , "README.md" )
520
526
fh , err := workingCopy .Open (sourcePath )
521
527
if err != nil {
522
528
if os .IsNotExist (err ) {
@@ -544,8 +550,8 @@ func (g generator) extractReadme(ctx context.Context, moduleAddr ModuleAddr, ver
544
550
_ = fh .Close ()
545
551
}
546
552
readmePath := path .Join (moduleAddr .Namespace , moduleAddr .Name , moduleAddr .TargetSystem , string (ver .ID ), "README.md" )
547
- if prefix != "" {
548
- readmePath = path .Join (moduleAddr .Namespace , moduleAddr .Name , moduleAddr .TargetSystem , string (ver .ID ), prefix , "README.md" )
553
+ if dstPrefix != "" {
554
+ readmePath = path .Join (moduleAddr .Namespace , moduleAddr .Name , moduleAddr .TargetSystem , string (ver .ID ), dstPrefix , "README.md" )
549
555
}
550
556
if err := g .storage .WriteFile (ctx , indexstorage .Path (readmePath ), readme ); err != nil {
551
557
return hasReadme , "" , fmt .Errorf ("failed to write README.md at %s (%w)" , readmePath , err )
@@ -593,9 +599,15 @@ func (g generator) extractSubmodules(ctx context.Context, addr ModuleAddr, ver M
593
599
Resources : []Resource {},
594
600
},
595
601
}
596
- submodulePrefix := path .Join (directoryPrefix , name )
597
- if err := g .refreshModuleDetails (ctx , addr , ver , & submodule .Details , workingCopy , licenseOK , blocked , blockedReason , submodulePrefix ); err != nil {
598
- return fmt .Errorf ("failed to refresh details for submodule %s (%w)" , submodulePrefix , err )
602
+ sourcePrefix := path .Join (directoryPrefix , name )
603
+ dstPrefix , err := g .sanitizePath (directoryPrefix , name )
604
+ if err != nil {
605
+ // Invalid path, ignore.
606
+ g .log .Warn (ctx , "Failed to index %s version %s submodule %s (%v)" , addr , ver .ID , dstPrefix , err )
607
+ continue
608
+ }
609
+ if err := g .refreshModuleDetails (ctx , addr , ver , & submodule .Details , workingCopy , licenseOK , blocked , blockedReason , sourcePrefix , dstPrefix ); err != nil {
610
+ return fmt .Errorf ("failed to refresh details for submodule %s (%w)" , sourcePrefix , err )
599
611
}
600
612
601
613
m .Submodules [name ] = submodule
@@ -630,7 +642,13 @@ func (g generator) extractExamples(ctx context.Context, moduleAddr ModuleAddr, v
630
642
Outputs : map [string ]Output {},
631
643
},
632
644
}
633
- examplePrefix := path .Join (directoryPrefix , name )
645
+ srcPrefix := path .Join (directoryPrefix , name )
646
+ dstPrefix , err := g .sanitizePath (directoryPrefix , name )
647
+ if err != nil {
648
+ // Invalid path, don't include in the index
649
+ g .log .Warn (ctx , "Failed to index %s version %s example %s (%v)" , moduleAddr , ver .ID , dstPrefix , err )
650
+ continue
651
+ }
634
652
if err := g .refreshExampleDetails (
635
653
ctx ,
636
654
moduleAddr ,
@@ -640,9 +658,10 @@ func (g generator) extractExamples(ctx context.Context, moduleAddr ModuleAddr, v
640
658
licenseOK ,
641
659
blocked ,
642
660
blockedReason ,
643
- examplePrefix ,
661
+ srcPrefix ,
662
+ dstPrefix ,
644
663
); err != nil {
645
- return fmt .Errorf ("failed to refresh details for example %s (%w)" , examplePrefix , err )
664
+ return fmt .Errorf ("failed to refresh details for example %s (%w)" , srcPrefix , err )
646
665
}
647
666
648
667
m .Examples [name ] = example
@@ -806,3 +825,8 @@ func (g generator) fetchRepoInfo(ctx context.Context, entry *Module) {
806
825
entry .UpstreamPopularity = upstreamRepoInfo .Popularity
807
826
entry .UpstreamForkCount = upstreamRepoInfo .ForkCount
808
827
}
828
+
829
+ func (g generator ) sanitizePath (prefix string , name string ) (string , error ) {
830
+ name = strings .ReplaceAll (name , " " , "" )
831
+ return path .Join (prefix , name ), indexstorage .Path (name ).Validate ()
832
+ }
0 commit comments