Merged
Conversation
sidepelican
approved these changes
Sep 18, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
現状と課題
現在
outputDirectoryに/を付け足しています。この変更は #117 で実装されていました。
コメントによるとディレクトリであることを保証したいようですが、
これは
Foundation.URLの取り扱いとしては変です。例えば以下のように末尾スラッシュをつけると、さらにそこにファイルを結合した時に、
パス文字列にダブルスラッシュが出現してしまいます。
実際、C2TSの動作ログで、ダブルスラッシュが含まれるパスが表示されてしまいます。
そもそも
URL型は、「そのパスがディレクトリかどうか」というフラグを内部で保持しています。これは、 init時に
isDirectory引数で指定することができます。引数を省略した場合は、ファイルシステムに問い合わせてディレクトリの実在性に基づいて設定されます。
この属性は、相対パスを解決する時などに動作に影響があります。
例えばウェブブラウザが
home/index.htmlを表示しているときに、login.htmlと書かれたリンクを踏んだ時、解決されるURLに影響します。index.htmlがファイルであれば、現在居るのはhomeディレクトリなので、home/login.htmlが宛先になります。もし
index.htmlがディレクトリであれば、現在いるのは
home/index.htmlディレクトリなので(拡張子から考えて不自然ですが)home/index.html/login.htmlが宛先になります。この
relativeToに指定したURLはbaseURLプロパティとして保持されていて、initで指定しなかった場合は暗黙にカレントディレクトリになっています。
pathを使うと結合結果が得られますが、relativePathを使うと自身のパス部分だけが得られます。C2TSではこの
relativePathを活用しているので、relativeTo,baseURL,isDirectoryも合わせて正しく使いたいです。また
URLはディレクトリを表す末尾スラッシュはパス表現としては含めず、パスの結合操作などの際に必要に応じてスラッシュを挿入します。
ただしfileスキームのURL形式で表示する場合は、ディレクトリならば末尾スラッシュをつけます。
自分で末尾スラッシュのパスをつけてしまうと、
pathComponentsなどの返す結果もちょっと変になります。URL形式だとそれだけでダブルスラッシュになってしまいます。
これは相対パスの解決処理などに影響する可能性もあります。
修正
initで受けた
outputDirectoryを操作して、isDirectoryがtrueのURLを作り直し、それを保持するようにします。他の案
initで受けた
outputDirectoryのhasDirectoryPathをみてfalseだったら例外を投げることを検討しました。互換性の問題が出そうなのと、この仕様を知らないと難しいので微妙かなと思いました。