This introduces `FilePath.addExtension` to take a path that we know has no prior extension, and append a new extension to it. As this function is simpler than `FilePath.withExtension`, this change eagerly replaces uses of the latter with the former, except in a few cases where stripping the extension really is the right thing to do. This should fix the bug described at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Import.20file.20with.20multiple.20dots.20in.20file.20name/near/404508048, where `import «A.B».«C.D.lean»` is needed to import `A.B/C.D.lean`. Closes #2999 --------- Co-authored-by: Mac Malone <tydeu@hatpress.net> Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
34 lines
968 B
Text
34 lines
968 B
Text
open System
|
|
open System.Platform
|
|
|
|
def norm (f : FilePath) : String :=
|
|
f.toString.map fun c => if c == '\\' then '/' else c
|
|
|
|
#eval FilePath.isAbsolute (if isWindows then "C:\\foo" else "/foo")
|
|
#eval FilePath.isAbsolute "a/b"
|
|
|
|
#eval norm <| ("a" : FilePath) / "b"
|
|
#eval norm <| ("a" : FilePath) / "b" / "c"
|
|
#eval norm <| ("a" : FilePath) / "/b/c"
|
|
|
|
#eval norm <$> FilePath.parent "a/b"
|
|
#eval norm <$> FilePath.parent "a/b/c"
|
|
#eval norm <$> FilePath.parent "a"
|
|
|
|
#eval FilePath.fileName "a/b"
|
|
|
|
#eval FilePath.fileStem "a/b"
|
|
#eval FilePath.fileStem "a/b.tar.gz"
|
|
#eval FilePath.fileStem "a/.gitignore"
|
|
|
|
#eval norm <| FilePath.withFileName "a/b" "c"
|
|
|
|
#eval FilePath.extension "a/b"
|
|
#eval FilePath.extension "a/b.txt"
|
|
#eval FilePath.extension "a/.gitignore"
|
|
|
|
#eval norm <| FilePath.withExtension "a/b.tar.gz" "xz"
|
|
#eval norm <| FilePath.withExtension "a/b.tar.gz" ""
|
|
#eval norm <| FilePath.withExtension "a/b" "tar.gz"
|
|
|
|
#eval norm <| FilePath.addExtension "a/b.tar.gz" "bak"
|