makeRelative
Contract a filename, based on a relative path. Note that the resulting
path will never introduce
.. paths, as the presence of
symlinks means
../b may not reach
a/b if it starts
from
a/c. For a worked example see
this blog post.
The corresponding
makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
Windows: makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
Windows: makeRelative "C:\\Home" "c:/home/bob" == "bob"
Windows: makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
Windows: makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
Windows: makeRelative "/Home" "/home/bob" == "bob"
Windows: makeRelative "/" "//" == "//"
Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
Posix: makeRelative "/fred" "bob" == "bob"
Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Contract a filename, based on a relative path. Note that the resulting
path will never introduce
.. paths, as the presence of
symlinks means
../b may not reach
a/b if it starts
from
a/c. For a worked example see
this blog post.
The corresponding
makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
Windows: makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
Windows: makeRelative "C:\\Home" "c:/home/bob" == "bob"
Windows: makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
Windows: makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
Windows: makeRelative "/Home" "/home/bob" == "bob"
Windows: makeRelative "/" "//" == "//"
Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
Posix: makeRelative "/fred" "bob" == "bob"
Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Contract a filename, based on a relative path. Note that the resulting
path will never introduce
.. paths, as the presence of
symlinks means
../b may not reach
a/b if it starts
from
a/c. For a worked example see
this blog post.
The corresponding
makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
makeRelative "/Home" "/home/bob" == "/home/bob"
makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
makeRelative "/fred" "bob" == "bob"
makeRelative "/file/test" "/file/test/fred" == "fred"
makeRelative "/file/test" "/file/test/fred/" == "fred/"
makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Contract a filename, based on a relative path. Note that the resulting
path will never introduce
.. paths, as the presence of
symlinks means
../b may not reach
a/b if it starts
from
a/c. For a worked example see
this blog post.
The corresponding
makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
Windows: makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
Windows: makeRelative "C:\\Home" "c:/home/bob" == "bob"
Windows: makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
Windows: makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
Windows: makeRelative "/Home" "/home/bob" == "bob"
Windows: makeRelative "/" "//" == "//"
Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
Posix: makeRelative "/fred" "bob" == "bob"
Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Contract a filename, based on a relative path. Note that the resulting
path will never introduce
.. paths, as the presence of
symlinks means
../b may not reach
a/b if it starts
from
a/c. For a worked example see
this blog post.
The corresponding
makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
makeRelative "C:\\Home" "c:/home/bob" == "bob"
makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
makeRelative "/Home" "/home/bob" == "bob"
makeRelative "/" "//" == "//"
Make a path relative to a given directory.
This function can be used to construct a relative path by removing the
supplied
AbsDir from the front. It is a runtime
error if
the supplied
AbsPath doesn't start with the
AbsDir.
Path.makeRelative (absDir "/tmp/somedir") (absFile "/tmp/somedir/anotherdir/file.txt") == Posix.relFile "anotherdir/file.txt"
Path.makeRelative (absDir "/tmp/somedir") (absDir "/tmp/somedir/anotherdir/dir") == Posix.relDir "anotherdir/dir"
Path.makeRelative (absDir "c:\\tmp\\somedir") (absFile "C:\\Tmp\\SomeDir\\AnotherDir\\File.txt") == Windows.relFile "AnotherDir\\File.txt"
Path.makeRelative (absDir "c:\\tmp\\somedir") (absDir "c:\\tmp\\somedir\\anotherdir\\dir") == Windows.relDir "anotherdir\\dir"
Path.makeRelative (absDir "c:tmp\\somedir") (absDir "c:tmp\\somedir\\anotherdir\\dir") == Windows.relDir "anotherdir\\dir"
Contract a filename, based on a relative path.
There is no corresponding
makeAbsolute function, instead use
System.Directory.canonicalizePath which has the same effect.
Valid y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
makeRelative x x == "."
null y || equalFilePath (makeRelative x (x </> y)) y || null (takeFileName x)
Windows: makeRelative "C:/Home" "c:/home/bob" == "bob"
Windows: makeRelative "C:/Home" "D:/Home/Bob" == "D:/Home/Bob"
Windows: makeRelative "C:/Home" "C:Home/Bob" == "C:Home/Bob"
Windows: makeRelative "/Home" "/home/bob" == "bob"
Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
Posix: makeRelative "/fred" "bob" == "bob"
Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Contract a filename, based on a relative path. Note that the resulting
path will never introduce
.. paths, as the presence of
symlinks means
../b may not reach
a/b if it starts
from
a/c. For a worked example see
this blog post.
The corresponding
makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
Windows: makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
Windows: makeRelative "C:\\Home" "c:/home/bob" == "bob"
Windows: makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
Windows: makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
Windows: makeRelative "/Home" "/home/bob" == "bob"
Windows: makeRelative "/" "//" == "//"
Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
Posix: makeRelative "/fred" "bob" == "bob"
Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Construct a path relative to the current directory, similar to
makeRelative.
The operation may fail with the same exceptions as
getCurrentDirectory.
The input is a filepath, which if relative is offset by the package
root.
Take a predicate to infer the project root and a relative file path,
the given file path is then attached to the inferred project root
This function looks at the source location of the Haskell file calling
it, finds the first parent directory with a file matching the given
predicate, and uses that as the root directory for fixing the relative
path.
$(makeRelativeToLocationPredicate ((==) ".cabal" . takeExtension) "data/foo.txt" >>= embedFile)
Take a relative file path and attach it to the root of the current
project.
The idea here is that, when building with Stack, the build will always
be executed with a current working directory of the root of the
project (where your .cabal file is located). However, if you load up
multiple projects with
stack ghci, the working directory may
be something else entirely.
This function looks at the source location of the Haskell file calling
it, finds the first parent directory with a .cabal file, and uses that
as the root directory for fixing the relative path.
$(makeRelativeToProject "data/foo.txt" >>= embedFile)
Make a path relative to current working directory.
Make a path relative. Returns Nothing only when the given paths are on
different drives. This will try the pure function makeRelative first.
If that fails, the paths are canonicalised (removing any indirection
and symlinks) and a relative path is derived from there.
> -- Given that "/root/a/" is not a symlink
> makeRelativeEx "/root/a/" "/root/b/file.out"
Just "../b/file.out"
> -- Given that "/root/c/" is a symlink to "/root/e/f/g/"
> makeRelativeEx "/root/c/" "/root/b/file.out"
Just "../../../b/file.out"
> -- On Windows
> makeRelativeEx "C:\\foo" "D:\\foo\\bar"
Nothing
Make a
RelativePath, ensuring the path is not absolute, but
performing no further checks.
Given a canonical absolute path and canonical absolute dir, make the
path relative to the directory, including using ../.. if
necessary. Returns the original absolute path if it is not on the same
drive as the given dir.
Given a path (relative or absolute), make it relative to the current
directory, including using ../.. if necessary.
Given a path (relative or absolute), make it relative to the given
directory, including using ../.. if necessary.