twostraws / Ignite

A static site generator for Swift developers.
MIT License
986 stars 34 forks source link

URL.packageDirectory(from file:) runs into an infinte loop if it can't find Package.swift anywhere #27

Open dirk68-fu opened 4 weeks ago

dirk68-fu commented 4 weeks ago

If the extension URL.packageDirectory(from file:) can't find a file Package.swift in any parent directory it runs into an infinite loop. Hanging the whole publishing process before it even startet.

twostraws commented 4 weeks ago

Sorry about that! Would you like to contribute or a fix, or would you prefer that I create one?

dirk68-fu commented 4 weeks ago

Hi Paul, Thank you for your great work in the Swift community. I just started trying out Ignite and do not feel confident enough yet to supply a fix for the issue.

twostraws commented 4 weeks ago

That's okay! I've put it on my todo list and will get it done 👍

twostraws commented 4 weeks ago

Hmm… I'm wondering whether there's a very specific situation that triggers this – it seems to correctly bail out once the path has been searched extensively. Can you trace the problem through on your end and see what the flow is? From what I can see, the loop should exit when while currentURL.path().isEmpty == false fails.

dirk68-fu commented 3 weeks ago

Hi Paul.

It never gets empty. I set a breakpoint after the repeat:

(lldb) po currentURL.path()
"/Users/"
(lldb) po currentURL.path()
"/"
(lldb) po currentURL.path()
"/../"
(lldb) po currentURL.path()
"/../../"

and strangely:

po URL("/").deletingLastPathComponent()
 ▿ /../
  - _url : /../
piotrekjeremicz commented 3 weeks ago

Paul @twostraws, I found this bug during PublishingContext.empty implementation. I am not sure what was wrong, but the commit that fixed this issue presents two changes in the PublishingContextKey:

32. var url = URL("") changed to 32. var url = URL("https://example.com")

and

49. PublishingContext(for: EmptySite(), from: "") changed to 49. try! PublishingContext(for: EmptySite(), rootURL: URL.documentsDirectory).

Maybe this second line had something to do with it.

dirk68-fu commented 3 weeks ago

The problem seems to be that URL.packageDirectory(from file:) searches upwards for Package.swift and breaking the loop if it finds it or if the search path is empty. But it never gets empty after "/" as shown above.