Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim file paths with a platform-agnostic path separator #91

Merged
merged 1 commit into from
May 29, 2021
Merged

Trim file paths with a platform-agnostic path separator #91

merged 1 commit into from
May 29, 2021

Conversation

rdipardo
Copy link
Contributor

There is platform-dependent logic in how the loaders/postloader.fsx script determines the character length of file paths:

let chopLength =
if rootDir.EndsWith("\\") then rootDir.Length
else rootDir.Length + 1

On Unix-based platforms, the else branch is always executed, resulting in truncated paths like osts/post.md. When this gets passed to the generators/post.fsx script, Seq.find throws an unhandled KeyNotFoundException:

BROKEN: `dotnet fake build -t TestTemplate` | OS: (Debian) 10.5 | RID: linux-x64
Starting target 'TestTemplate'
templateDir: /home/rob/dev/Fornax/src/Fornax.Template/
/home/rob/dev/Fornax/src/Fornax.Template/> "dotnet" /home/rob/dev/Fornax/temp/Fornax.dll watch (In: false, Out: false, Err: false)
[19:20:24] multiple files generated in 530ms
[19:20:25] '/home/rob/dev/Fornax/src/Fornax.Template/_public/about.html' generated in 682ms
[19:20:25] '/home/rob/dev/Fornax/src/Fornax.Template/_public/contact.html' generated in 678ms
[../post.fsx,12] Does osts/post6.md match posts/post6.md ?
[../post.fsx,12] Does osts/post.md match posts/post6.md ?
[../post.fsx,12] Does osts/post2.md match posts/post6.md ?
[../post.fsx,12] Does osts/post4.md match posts/post6.md ?
[../post.fsx,12] Does osts/post5.md match posts/post6.md ?
[../post.fsx,12] Does osts/post3.md match posts/post6.md ?
[../post.fsx,12] Does osts/subdir/post3.md match posts/post6.md ?
An unexpected error happend: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Collections.Generic.KeyNotFoundException: An index satisfying the predicate was not found in the collection.
   at Microsoft.FSharp.Collections.SeqModule.Find[T](FSharpFunc`2 predicate, IEnumerable`1 source) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 677
   at FSI_0022.Post.generate'(SiteContents ctx, String page)
   at lambda_method21(Closure , Unit , SiteContents , String , String )
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Generator.EvaluatorHelpers.helper@56(Object next, FSharpList`1 args) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 66
   at Generator.EvaluatorHelpers.invokeFunction(Object f, IEnumerable`1 args) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 70
   at [email protected](Object generator) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 195
   at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
   at Generator.GeneratorEvaluator.evaluate(FsiEvaluationSession fsi, SiteContents siteContent, String generatorPath, String projectRoot, String page) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 190
   at Generator.generate(FsiEvaluationSession fsi, Config cfg, SiteContents siteContent, String projectRoot, String page) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 333
   at Generator.action@1-3(String projectRoot, FsiEvaluationSession fsi, Config config, SiteContents sc, String filePath) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 496
   at Generator.generateFolder(String projectRoot, Boolean isWatch) in /home/rob/dev/Fornax/src/Fornax/Generator.fs:line 495
   at Fornax.guardedGenerate@226(String cwd, Unit unitVar0) in /home/rob/dev/Fornax/src/Fornax/Fornax.fs:line 228
Finished (Failed) 'TestTemplate' in 00:00:24.6853931
PATCHED: `dotnet fake build -t TestTemplate` | OS: (Debian) 10.5 | RID: linux-x64
Starting target 'TestTemplate'
templateDir: /home/rob/dev/Fornax/src/Fornax.Template/
/home/rob/dev/Fornax/src/Fornax.Template/> "dotnet" /home/rob/dev/Fornax/temp/Fornax.dll watch (In: false, Out: false, Err: false)
[19:28:28] multiple files generated in 605ms
[19:28:29] '/home/rob/dev/Fornax/src/Fornax.Template/_public/about.html' generated in 781ms
[19:28:30] '/home/rob/dev/Fornax/src/Fornax.Template/_public/contact.html' generated in 722ms
[../post.fsx,12] Does posts/post6.md match posts/post6.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post6.html' generated in 909ms
[../post.fsx,12] Does posts/post6.md match posts/post.md ?
[../post.fsx,12] Does posts/post.md match posts/post.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post.html' generated in 3ms
[../post.fsx,12] Does posts/post6.md match posts/post2.md ?
[../post.fsx,12] Does posts/post.md match posts/post2.md ?
[../post.fsx,12] Does posts/post2.md match posts/post2.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post2.html' generated in 3ms
[../post.fsx,12] Does posts/post6.md match posts/post4.md ?
[../post.fsx,12] Does posts/post.md match posts/post4.md ?
[../post.fsx,12] Does posts/post2.md match posts/post4.md ?
[../post.fsx,12] Does posts/post4.md match posts/post4.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post4.html' generated in 3ms
[../post.fsx,12] Does posts/post6.md match posts/post5.md ?
[../post.fsx,12] Does posts/post.md match posts/post5.md ?
[../post.fsx,12] Does posts/post2.md match posts/post5.md ?
[../post.fsx,12] Does posts/post4.md match posts/post5.md ?
[../post.fsx,12] Does posts/post5.md match posts/post5.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post5.html' generated in 4ms
[../post.fsx,12] Does posts/post6.md match posts/post3.md ?
[../post.fsx,12] Does posts/post.md match posts/post3.md ?
[../post.fsx,12] Does posts/post2.md match posts/post3.md ?
[../post.fsx,12] Does posts/post4.md match posts/post3.md ?
[../post.fsx,12] Does posts/post5.md match posts/post3.md ?
[../post.fsx,12] Does posts/post3.md match posts/post3.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/post3.html' generated in 4ms
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/js/sampleJsFile.js' generated in 141ms
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/images/avatar.jpg' generated in 1ms
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/images/bulma.png' generated in 1ms
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/images/favicon.png' generated in 1ms
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/style/style.css' generated in 1ms
[../post.fsx,12] Does posts/post6.md match posts/subdir/post3.md ?
[../post.fsx,12] Does posts/post.md match posts/subdir/post3.md ?
[../post.fsx,12] Does posts/post2.md match posts/subdir/post3.md ?
[../post.fsx,12] Does posts/post4.md match posts/subdir/post3.md ?
[../post.fsx,12] Does posts/post5.md match posts/subdir/post3.md ?
[../post.fsx,12] Does posts/post3.md match posts/subdir/post3.md ?
[../post.fsx,12] Does posts/subdir/post3.md match posts/subdir/post3.md ?
[19:28:31] '/home/rob/dev/Fornax/src/Fornax.Template/_public/posts/subdir/post3.html' generated in 4ms
Generation time: 00:00:23.4658193
[19:28:31] Watch mode started. Press any key to exit.
[19:28:31 INF] Smooth! Suave listener started in 143.693ms with binding 127.0.0.1:8080

This partly addresses the issue reported at #84.

@baronfel
Copy link
Contributor

Nice find, thanks!

@baronfel baronfel merged commit e681704 into ionide:master May 29, 2021
@rdipardo rdipardo deleted the fix/use-universal-dir-sep branch June 6, 2021 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants