835 lines
110 KiB
HTML
835 lines
110 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html>
|
|
<head>
|
|
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
|
|
<title>src/System/Posix/FilePath.hs</title>
|
|
<link type='text/css' rel='stylesheet' href='hscolour.css' />
|
|
</head>
|
|
<body>
|
|
<pre><a name="line-1"></a><span class='hs-comment'>-- |</span>
|
|
<a name="line-2"></a><span class='hs-comment'>-- Module : System.Posix.FilePath</span>
|
|
<a name="line-3"></a><span class='hs-comment'>-- Copyright : © 2016 Julian Ospald</span>
|
|
<a name="line-4"></a><span class='hs-comment'>-- License : BSD3</span>
|
|
<a name="line-5"></a><span class='hs-comment'>--</span>
|
|
<a name="line-6"></a><span class='hs-comment'>-- Maintainer : Julian Ospald <hasufell@posteo.de></span>
|
|
<a name="line-7"></a><span class='hs-comment'>-- Stability : experimental</span>
|
|
<a name="line-8"></a><span class='hs-comment'>-- Portability : portable</span>
|
|
<a name="line-9"></a><span class='hs-comment'>--</span>
|
|
<a name="line-10"></a><span class='hs-comment'>-- The equivalent of "System.FilePath" on raw (byte string) file paths.</span>
|
|
<a name="line-11"></a><span class='hs-comment'>--</span>
|
|
<a name="line-12"></a><span class='hs-comment'>-- Not all functions of "System.FilePath" are implemented yet. Feel free to contribute!</span>
|
|
<a name="line-13"></a>
|
|
<a name="line-14"></a>
|
|
<a name="line-15"></a><span class='hs-comment'>{-# LANGUAGE CPP #-}</span>
|
|
<a name="line-16"></a><span class='hs-comment'>{-# LANGUAGE TupleSections #-}</span>
|
|
<a name="line-17"></a>
|
|
<a name="line-18"></a><span class='hs-comment'>{-# OPTIONS_GHC -Wall #-}</span>
|
|
<a name="line-19"></a>
|
|
<a name="line-20"></a>
|
|
<a name="line-21"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>Posix</span><span class='hs-varop'>.</span><span class='hs-conid'>FilePath</span> <span class='hs-layout'>(</span>
|
|
<a name="line-22"></a>
|
|
<a name="line-23"></a> <span class='hs-comment'>-- * Separator predicates</span>
|
|
<a name="line-24"></a> <span class='hs-varid'>pathSeparator</span>
|
|
<a name="line-25"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isPathSeparator</span>
|
|
<a name="line-26"></a><span class='hs-layout'>,</span> <span class='hs-varid'>searchPathSeparator</span>
|
|
<a name="line-27"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isSearchPathSeparator</span>
|
|
<a name="line-28"></a><span class='hs-layout'>,</span> <span class='hs-varid'>extSeparator</span>
|
|
<a name="line-29"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isExtSeparator</span>
|
|
<a name="line-30"></a>
|
|
<a name="line-31"></a> <span class='hs-comment'>-- * $PATH methods</span>
|
|
<a name="line-32"></a><span class='hs-layout'>,</span> <span class='hs-varid'>splitSearchPath</span>
|
|
<a name="line-33"></a><span class='hs-layout'>,</span> <span class='hs-varid'>getSearchPath</span>
|
|
<a name="line-34"></a>
|
|
<a name="line-35"></a> <span class='hs-comment'>-- * Extension functions</span>
|
|
<a name="line-36"></a><span class='hs-layout'>,</span> <span class='hs-varid'>splitExtension</span>
|
|
<a name="line-37"></a><span class='hs-layout'>,</span> <span class='hs-varid'>takeExtension</span>
|
|
<a name="line-38"></a><span class='hs-layout'>,</span> <span class='hs-varid'>replaceExtension</span>
|
|
<a name="line-39"></a><span class='hs-layout'>,</span> <span class='hs-varid'>dropExtension</span>
|
|
<a name="line-40"></a><span class='hs-layout'>,</span> <span class='hs-varid'>addExtension</span>
|
|
<a name="line-41"></a><span class='hs-layout'>,</span> <span class='hs-varid'>hasExtension</span>
|
|
<a name="line-42"></a><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'><.></span><span class='hs-layout'>)</span>
|
|
<a name="line-43"></a><span class='hs-layout'>,</span> <span class='hs-varid'>splitExtensions</span>
|
|
<a name="line-44"></a><span class='hs-layout'>,</span> <span class='hs-varid'>dropExtensions</span>
|
|
<a name="line-45"></a><span class='hs-layout'>,</span> <span class='hs-varid'>takeExtensions</span>
|
|
<a name="line-46"></a><span class='hs-layout'>,</span> <span class='hs-varid'>stripExtension</span>
|
|
<a name="line-47"></a>
|
|
<a name="line-48"></a> <span class='hs-comment'>-- * Filename\/directory functions</span>
|
|
<a name="line-49"></a><span class='hs-layout'>,</span> <span class='hs-varid'>splitFileName</span>
|
|
<a name="line-50"></a><span class='hs-layout'>,</span> <span class='hs-varid'>takeFileName</span>
|
|
<a name="line-51"></a><span class='hs-layout'>,</span> <span class='hs-varid'>replaceFileName</span>
|
|
<a name="line-52"></a><span class='hs-layout'>,</span> <span class='hs-varid'>dropFileName</span>
|
|
<a name="line-53"></a><span class='hs-layout'>,</span> <span class='hs-varid'>takeBaseName</span>
|
|
<a name="line-54"></a><span class='hs-layout'>,</span> <span class='hs-varid'>replaceBaseName</span>
|
|
<a name="line-55"></a><span class='hs-layout'>,</span> <span class='hs-varid'>takeDirectory</span>
|
|
<a name="line-56"></a><span class='hs-layout'>,</span> <span class='hs-varid'>replaceDirectory</span>
|
|
<a name="line-57"></a><span class='hs-layout'>,</span> <span class='hs-varid'>combine</span>
|
|
<a name="line-58"></a><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'></></span><span class='hs-layout'>)</span>
|
|
<a name="line-59"></a><span class='hs-layout'>,</span> <span class='hs-varid'>splitPath</span>
|
|
<a name="line-60"></a><span class='hs-layout'>,</span> <span class='hs-varid'>joinPath</span>
|
|
<a name="line-61"></a><span class='hs-layout'>,</span> <span class='hs-varid'>splitDirectories</span>
|
|
<a name="line-62"></a>
|
|
<a name="line-63"></a> <span class='hs-comment'>-- * Trailing slash functions</span>
|
|
<a name="line-64"></a><span class='hs-layout'>,</span> <span class='hs-varid'>hasTrailingPathSeparator</span>
|
|
<a name="line-65"></a><span class='hs-layout'>,</span> <span class='hs-varid'>addTrailingPathSeparator</span>
|
|
<a name="line-66"></a><span class='hs-layout'>,</span> <span class='hs-varid'>dropTrailingPathSeparator</span>
|
|
<a name="line-67"></a>
|
|
<a name="line-68"></a> <span class='hs-comment'>-- * File name manipulations</span>
|
|
<a name="line-69"></a><span class='hs-layout'>,</span> <span class='hs-varid'>normalise</span>
|
|
<a name="line-70"></a><span class='hs-layout'>,</span> <span class='hs-varid'>makeRelative</span>
|
|
<a name="line-71"></a><span class='hs-layout'>,</span> <span class='hs-varid'>equalFilePath</span>
|
|
<a name="line-72"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isRelative</span>
|
|
<a name="line-73"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isAbsolute</span>
|
|
<a name="line-74"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isValid</span>
|
|
<a name="line-75"></a><span class='hs-layout'>,</span> <span class='hs-varid'>makeValid</span>
|
|
<a name="line-76"></a><span class='hs-layout'>,</span> <span class='hs-varid'>isFileName</span>
|
|
<a name="line-77"></a><span class='hs-layout'>,</span> <span class='hs-varid'>hasParentDir</span>
|
|
<a name="line-78"></a><span class='hs-layout'>,</span> <span class='hs-varid'>hiddenFile</span>
|
|
<a name="line-79"></a>
|
|
<a name="line-80"></a><span class='hs-layout'>,</span> <span class='hs-keyword'>module</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>Posix</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>FilePath</span>
|
|
<a name="line-81"></a><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
|
|
<a name="line-82"></a>
|
|
<a name="line-83"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-layout'>(</span><span class='hs-conid'>ByteString</span><span class='hs-layout'>)</span>
|
|
<a name="line-84"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>BS</span>
|
|
<a name="line-85"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>String</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromString</span><span class='hs-layout'>)</span>
|
|
<a name="line-86"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>Posix</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>FilePath</span>
|
|
<a name="line-87"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>Posix</span><span class='hs-varop'>.</span><span class='hs-conid'>Env</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>PE</span>
|
|
<a name="line-88"></a>
|
|
<a name="line-89"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Maybe</span> <span class='hs-layout'>(</span><span class='hs-varid'>isJust</span><span class='hs-layout'>)</span>
|
|
<a name="line-90"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Word8</span>
|
|
<a name="line-91"></a><span class='hs-cpp'>#if !MIN_VERSION_bytestring(0,10,8)</span>
|
|
<a name="line-92"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>List</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>L</span>
|
|
<a name="line-93"></a><span class='hs-cpp'>#endif</span>
|
|
<a name="line-94"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Arrow</span> <span class='hs-layout'>(</span><span class='hs-varid'>second</span><span class='hs-layout'>)</span>
|
|
<a name="line-95"></a>
|
|
<a name="line-96"></a><span class='hs-comment'>-- $setup</span>
|
|
<a name="line-97"></a><span class='hs-comment'>-- >>> import Data.Char</span>
|
|
<a name="line-98"></a><span class='hs-comment'>-- >>> import Data.Maybe</span>
|
|
<a name="line-99"></a><span class='hs-comment'>-- >>> import Test.QuickCheck</span>
|
|
<a name="line-100"></a><span class='hs-comment'>-- >>> import Control.Applicative</span>
|
|
<a name="line-101"></a><span class='hs-comment'>-- >>> import qualified Data.ByteString as BS</span>
|
|
<a name="line-102"></a><span class='hs-comment'>-- >>> instance Arbitrary ByteString where arbitrary = BS.pack <$> arbitrary</span>
|
|
<a name="line-103"></a><span class='hs-comment'>-- >>> instance CoArbitrary ByteString where coarbitrary = coarbitrary . BS.unpack</span>
|
|
<a name="line-104"></a><span class='hs-comment'>--</span>
|
|
<a name="line-105"></a><span class='hs-comment'>-- >>> let _chr :: Word8 -> Char; _chr = chr . fromIntegral</span>
|
|
<a name="line-106"></a>
|
|
<a name="line-107"></a>
|
|
<a name="line-108"></a>
|
|
<a name="line-109"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-110"></a><span class='hs-comment'>-- Separator predicates</span>
|
|
<a name="line-111"></a>
|
|
<a name="line-112"></a>
|
|
<a name="line-113"></a><a name="pathSeparator"></a><span class='hs-comment'>-- | Path separator character</span>
|
|
<a name="line-114"></a><span class='hs-definition'>pathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span>
|
|
<a name="line-115"></a><span class='hs-definition'>pathSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-sel'>_slash</span>
|
|
<a name="line-116"></a>
|
|
<a name="line-117"></a>
|
|
<a name="line-118"></a><a name="isPathSeparator"></a><span class='hs-comment'>-- | Check if a character is the path separator</span>
|
|
<a name="line-119"></a><span class='hs-comment'>--</span>
|
|
<a name="line-120"></a><span class='hs-comment'>-- prop> \n -> (_chr n == '/') == isPathSeparator n</span>
|
|
<a name="line-121"></a><span class='hs-definition'>isPathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-122"></a><span class='hs-definition'>isPathSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-varid'>pathSeparator</span><span class='hs-layout'>)</span>
|
|
<a name="line-123"></a>
|
|
<a name="line-124"></a>
|
|
<a name="line-125"></a><a name="searchPathSeparator"></a><span class='hs-comment'>-- | Search path separator</span>
|
|
<a name="line-126"></a><span class='hs-definition'>searchPathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span>
|
|
<a name="line-127"></a><span class='hs-definition'>searchPathSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-sel'>_colon</span>
|
|
<a name="line-128"></a>
|
|
<a name="line-129"></a>
|
|
<a name="line-130"></a><a name="isSearchPathSeparator"></a><span class='hs-comment'>-- | Check if a character is the search path separator</span>
|
|
<a name="line-131"></a><span class='hs-comment'>--</span>
|
|
<a name="line-132"></a><span class='hs-comment'>-- prop> \n -> (_chr n == ':') == isSearchPathSeparator n</span>
|
|
<a name="line-133"></a><span class='hs-definition'>isSearchPathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-134"></a><span class='hs-definition'>isSearchPathSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-varid'>searchPathSeparator</span><span class='hs-layout'>)</span>
|
|
<a name="line-135"></a>
|
|
<a name="line-136"></a>
|
|
<a name="line-137"></a><a name="extSeparator"></a><span class='hs-comment'>-- | File extension separator</span>
|
|
<a name="line-138"></a><span class='hs-definition'>extSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span>
|
|
<a name="line-139"></a><span class='hs-definition'>extSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-sel'>_period</span>
|
|
<a name="line-140"></a>
|
|
<a name="line-141"></a>
|
|
<a name="line-142"></a><a name="isExtSeparator"></a><span class='hs-comment'>-- | Check if a character is the file extension separator</span>
|
|
<a name="line-143"></a><span class='hs-comment'>--</span>
|
|
<a name="line-144"></a><span class='hs-comment'>-- prop> \n -> (_chr n == '.') == isExtSeparator n</span>
|
|
<a name="line-145"></a><span class='hs-definition'>isExtSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-146"></a><span class='hs-definition'>isExtSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-varid'>extSeparator</span><span class='hs-layout'>)</span>
|
|
<a name="line-147"></a>
|
|
<a name="line-148"></a>
|
|
<a name="line-149"></a>
|
|
<a name="line-150"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-151"></a><span class='hs-comment'>-- $PATH methods</span>
|
|
<a name="line-152"></a>
|
|
<a name="line-153"></a>
|
|
<a name="line-154"></a><a name="splitSearchPath"></a><span class='hs-comment'>-- | Take a ByteString, split it on the 'searchPathSeparator'.</span>
|
|
<a name="line-155"></a><span class='hs-comment'>-- Blank items are converted to @.@.</span>
|
|
<a name="line-156"></a><span class='hs-comment'>--</span>
|
|
<a name="line-157"></a><span class='hs-comment'>-- Follows the recommendations in</span>
|
|
<a name="line-158"></a><span class='hs-comment'>-- <<a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html">http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html</a>></span>
|
|
<a name="line-159"></a><span class='hs-comment'>--</span>
|
|
<a name="line-160"></a><span class='hs-comment'>-- >>> splitSearchPath "File1:File2:File3"</span>
|
|
<a name="line-161"></a><span class='hs-comment'>-- ["File1","File2","File3"]</span>
|
|
<a name="line-162"></a><span class='hs-comment'>-- >>> splitSearchPath "File1::File2:File3"</span>
|
|
<a name="line-163"></a><span class='hs-comment'>-- ["File1",".","File2","File3"]</span>
|
|
<a name="line-164"></a><span class='hs-comment'>-- >>> splitSearchPath ""</span>
|
|
<a name="line-165"></a><span class='hs-comment'>-- ["."]</span>
|
|
<a name="line-166"></a><span class='hs-definition'>splitSearchPath</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>RawFilePath</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-167"></a><span class='hs-definition'>splitSearchPath</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span>
|
|
<a name="line-168"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-169"></a> <span class='hs-varid'>f</span> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>pre</span><span class='hs-layout'>,</span> <span class='hs-varid'>post</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>break</span> <span class='hs-varid'>isSearchPathSeparator</span> <span class='hs-varid'>bs</span>
|
|
<a name="line-170"></a> <span class='hs-keyword'>in</span> <span class='hs-keyword'>if</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>post</span>
|
|
<a name="line-171"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>g</span> <span class='hs-varid'>pre</span>
|
|
<a name="line-172"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>g</span> <span class='hs-varid'>pre</span> <span class='hs-varop'>++</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>tail</span> <span class='hs-varid'>post</span><span class='hs-layout'>)</span>
|
|
<a name="line-173"></a> <span class='hs-varid'>g</span> <span class='hs-varid'>x</span>
|
|
<a name="line-174"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-sel'>_period</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-175"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-176"></a>
|
|
<a name="line-177"></a>
|
|
<a name="line-178"></a><a name="getSearchPath"></a><span class='hs-comment'>-- | Get a list of 'RawFilePath's in the $PATH variable.</span>
|
|
<a name="line-179"></a><span class='hs-definition'>getSearchPath</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>IO</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>RawFilePath</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-180"></a><span class='hs-definition'>getSearchPath</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-varid'>maybe</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>splitSearchPath</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>PE</span><span class='hs-varop'>.</span><span class='hs-varid'>getEnv</span> <span class='hs-varop'>$</span> <span class='hs-varid'>fromString</span> <span class='hs-str'>"PATH"</span><span class='hs-layout'>)</span>
|
|
<a name="line-181"></a>
|
|
<a name="line-182"></a>
|
|
<a name="line-183"></a>
|
|
<a name="line-184"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-185"></a><span class='hs-comment'>-- Extension functions</span>
|
|
<a name="line-186"></a>
|
|
<a name="line-187"></a><a name="splitExtension"></a><span class='hs-comment'>-- | Split a 'RawFilePath' into a path+filename and extension</span>
|
|
<a name="line-188"></a><span class='hs-comment'>--</span>
|
|
<a name="line-189"></a><span class='hs-comment'>-- >>> splitExtension "file.exe"</span>
|
|
<a name="line-190"></a><span class='hs-comment'>-- ("file",".exe")</span>
|
|
<a name="line-191"></a><span class='hs-comment'>-- >>> splitExtension "file"</span>
|
|
<a name="line-192"></a><span class='hs-comment'>-- ("file","")</span>
|
|
<a name="line-193"></a><span class='hs-comment'>-- >>> splitExtension "/path/file.tar.gz"</span>
|
|
<a name="line-194"></a><span class='hs-comment'>-- ("/path/file.tar",".gz")</span>
|
|
<a name="line-195"></a><span class='hs-comment'>--</span>
|
|
<a name="line-196"></a><span class='hs-comment'>-- prop> \path -> uncurry (BS.append) (splitExtension path) == path</span>
|
|
<a name="line-197"></a><span class='hs-definition'>splitExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>RawFilePath</span><span class='hs-layout'>,</span> <span class='hs-conid'>ByteString</span><span class='hs-layout'>)</span>
|
|
<a name="line-198"></a><span class='hs-definition'>splitExtension</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>basename</span>
|
|
<a name="line-199"></a> <span class='hs-keyword'>then</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>empty</span><span class='hs-layout'>)</span>
|
|
<a name="line-200"></a> <span class='hs-keyword'>else</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span> <span class='hs-varid'>path</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>init</span> <span class='hs-varid'>basename</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>cons</span> <span class='hs-varid'>extSeparator</span> <span class='hs-varid'>fileExt</span><span class='hs-layout'>)</span>
|
|
<a name="line-201"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-202"></a> <span class='hs-layout'>(</span><span class='hs-varid'>path</span><span class='hs-layout'>,</span><span class='hs-varid'>file</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitFileNameRaw</span> <span class='hs-varid'>x</span>
|
|
<a name="line-203"></a> <span class='hs-layout'>(</span><span class='hs-varid'>basename</span><span class='hs-layout'>,</span><span class='hs-varid'>fileExt</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>breakEnd</span> <span class='hs-varid'>isExtSeparator</span> <span class='hs-varid'>file</span>
|
|
<a name="line-204"></a>
|
|
<a name="line-205"></a>
|
|
<a name="line-206"></a><a name="takeExtension"></a><span class='hs-comment'>-- | Get the final extension from a 'RawFilePath'</span>
|
|
<a name="line-207"></a><span class='hs-comment'>--</span>
|
|
<a name="line-208"></a><span class='hs-comment'>-- >>> takeExtension "file.exe"</span>
|
|
<a name="line-209"></a><span class='hs-comment'>-- ".exe"</span>
|
|
<a name="line-210"></a><span class='hs-comment'>-- >>> takeExtension "file"</span>
|
|
<a name="line-211"></a><span class='hs-comment'>-- ""</span>
|
|
<a name="line-212"></a><span class='hs-comment'>-- >>> takeExtension "/path/file.tar.gz"</span>
|
|
<a name="line-213"></a><span class='hs-comment'>-- ".gz"</span>
|
|
<a name="line-214"></a><span class='hs-definition'>takeExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span>
|
|
<a name="line-215"></a><span class='hs-definition'>takeExtension</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>snd</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitExtension</span>
|
|
<a name="line-216"></a>
|
|
<a name="line-217"></a>
|
|
<a name="line-218"></a><a name="replaceExtension"></a><span class='hs-comment'>-- | Change a file's extension</span>
|
|
<a name="line-219"></a><span class='hs-comment'>--</span>
|
|
<a name="line-220"></a><span class='hs-comment'>-- prop> \path -> let ext = takeExtension path in replaceExtension path ext == path</span>
|
|
<a name="line-221"></a><span class='hs-definition'>replaceExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-222"></a><span class='hs-definition'>replaceExtension</span> <span class='hs-varid'>path</span> <span class='hs-varid'>ext</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>dropExtension</span> <span class='hs-varid'>path</span> <span class='hs-varop'><.></span> <span class='hs-varid'>ext</span>
|
|
<a name="line-223"></a>
|
|
<a name="line-224"></a>
|
|
<a name="line-225"></a><a name="dropExtension"></a><span class='hs-comment'>-- | Drop the final extension from a 'RawFilePath'</span>
|
|
<a name="line-226"></a><span class='hs-comment'>--</span>
|
|
<a name="line-227"></a><span class='hs-comment'>-- >>> dropExtension "file.exe"</span>
|
|
<a name="line-228"></a><span class='hs-comment'>-- "file"</span>
|
|
<a name="line-229"></a><span class='hs-comment'>-- >>> dropExtension "file"</span>
|
|
<a name="line-230"></a><span class='hs-comment'>-- "file"</span>
|
|
<a name="line-231"></a><span class='hs-comment'>-- >>> dropExtension "/path/file.tar.gz"</span>
|
|
<a name="line-232"></a><span class='hs-comment'>-- "/path/file.tar"</span>
|
|
<a name="line-233"></a><span class='hs-definition'>dropExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-234"></a><span class='hs-definition'>dropExtension</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fst</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitExtension</span>
|
|
<a name="line-235"></a>
|
|
<a name="line-236"></a>
|
|
<a name="line-237"></a><a name="addExtension"></a><span class='hs-comment'>-- | Add an extension to a 'RawFilePath'</span>
|
|
<a name="line-238"></a><span class='hs-comment'>--</span>
|
|
<a name="line-239"></a><span class='hs-comment'>-- >>> addExtension "file" ".exe"</span>
|
|
<a name="line-240"></a><span class='hs-comment'>-- "file.exe"</span>
|
|
<a name="line-241"></a><span class='hs-comment'>-- >>> addExtension "file.tar" ".gz"</span>
|
|
<a name="line-242"></a><span class='hs-comment'>-- "file.tar.gz"</span>
|
|
<a name="line-243"></a><span class='hs-comment'>-- >>> addExtension "/path/" ".ext"</span>
|
|
<a name="line-244"></a><span class='hs-comment'>-- "/path/.ext"</span>
|
|
<a name="line-245"></a><span class='hs-definition'>addExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-246"></a><span class='hs-definition'>addExtension</span> <span class='hs-varid'>file</span> <span class='hs-varid'>ext</span>
|
|
<a name="line-247"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>ext</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>file</span>
|
|
<a name="line-248"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>isExtSeparator</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>head</span> <span class='hs-varid'>ext</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span> <span class='hs-varid'>file</span> <span class='hs-varid'>ext</span>
|
|
<a name="line-249"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>intercalate</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>extSeparator</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>file</span><span class='hs-layout'>,</span> <span class='hs-varid'>ext</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-250"></a>
|
|
<a name="line-251"></a>
|
|
<a name="line-252"></a><a name="hasExtension"></a><span class='hs-comment'>-- | Check if a 'RawFilePath' has an extension</span>
|
|
<a name="line-253"></a><span class='hs-comment'>--</span>
|
|
<a name="line-254"></a><span class='hs-comment'>-- >>> hasExtension "file"</span>
|
|
<a name="line-255"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-256"></a><span class='hs-comment'>-- >>> hasExtension "file.tar"</span>
|
|
<a name="line-257"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-258"></a><span class='hs-comment'>-- >>> hasExtension "/path.part1/"</span>
|
|
<a name="line-259"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-260"></a><span class='hs-definition'>hasExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-261"></a><span class='hs-definition'>hasExtension</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>isJust</span> <span class='hs-varop'>.</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>elemIndex</span> <span class='hs-varid'>extSeparator</span> <span class='hs-varop'>.</span> <span class='hs-varid'>takeFileName</span>
|
|
<a name="line-262"></a>
|
|
<a name="line-263"></a>
|
|
<a name="line-264"></a><a name="%3c.%3e"></a><span class='hs-comment'>-- | Operator version of 'addExtension'</span>
|
|
<a name="line-265"></a><span class='hs-layout'>(</span><span class='hs-varop'><.></span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-266"></a><span class='hs-layout'>(</span><span class='hs-varop'><.></span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>addExtension</span>
|
|
<a name="line-267"></a>
|
|
<a name="line-268"></a>
|
|
<a name="line-269"></a><a name="splitExtensions"></a><span class='hs-comment'>-- | Split a 'RawFilePath' on the first extension.</span>
|
|
<a name="line-270"></a><span class='hs-comment'>--</span>
|
|
<a name="line-271"></a><span class='hs-comment'>-- >>> splitExtensions "/path/file.tar.gz"</span>
|
|
<a name="line-272"></a><span class='hs-comment'>-- ("/path/file",".tar.gz")</span>
|
|
<a name="line-273"></a><span class='hs-comment'>--</span>
|
|
<a name="line-274"></a><span class='hs-comment'>-- prop> \path -> uncurry addExtension (splitExtensions path) == path</span>
|
|
<a name="line-275"></a><span class='hs-definition'>splitExtensions</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>RawFilePath</span><span class='hs-layout'>,</span> <span class='hs-conid'>ByteString</span><span class='hs-layout'>)</span>
|
|
<a name="line-276"></a><span class='hs-definition'>splitExtensions</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>basename</span>
|
|
<a name="line-277"></a> <span class='hs-keyword'>then</span> <span class='hs-layout'>(</span><span class='hs-varid'>path</span><span class='hs-layout'>,</span><span class='hs-varid'>fileExt</span><span class='hs-layout'>)</span>
|
|
<a name="line-278"></a> <span class='hs-keyword'>else</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span> <span class='hs-varid'>path</span> <span class='hs-varid'>basename</span><span class='hs-layout'>,</span><span class='hs-varid'>fileExt</span><span class='hs-layout'>)</span>
|
|
<a name="line-279"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-280"></a> <span class='hs-layout'>(</span><span class='hs-varid'>path</span><span class='hs-layout'>,</span><span class='hs-varid'>file</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitFileNameRaw</span> <span class='hs-varid'>x</span>
|
|
<a name="line-281"></a> <span class='hs-layout'>(</span><span class='hs-varid'>basename</span><span class='hs-layout'>,</span><span class='hs-varid'>fileExt</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>break</span> <span class='hs-varid'>isExtSeparator</span> <span class='hs-varid'>file</span>
|
|
<a name="line-282"></a>
|
|
<a name="line-283"></a>
|
|
<a name="line-284"></a><a name="dropExtensions"></a><span class='hs-comment'>-- | Remove all extensions from a 'RawFilePath'</span>
|
|
<a name="line-285"></a><span class='hs-comment'>--</span>
|
|
<a name="line-286"></a><span class='hs-comment'>-- >>> dropExtensions "/path/file.tar.gz"</span>
|
|
<a name="line-287"></a><span class='hs-comment'>-- "/path/file"</span>
|
|
<a name="line-288"></a><span class='hs-definition'>dropExtensions</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-289"></a><span class='hs-definition'>dropExtensions</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fst</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitExtensions</span>
|
|
<a name="line-290"></a>
|
|
<a name="line-291"></a>
|
|
<a name="line-292"></a><a name="takeExtensions"></a><span class='hs-comment'>-- | Take all extensions from a 'RawFilePath'</span>
|
|
<a name="line-293"></a><span class='hs-comment'>--</span>
|
|
<a name="line-294"></a><span class='hs-comment'>-- >>> takeExtensions "/path/file.tar.gz"</span>
|
|
<a name="line-295"></a><span class='hs-comment'>-- ".tar.gz"</span>
|
|
<a name="line-296"></a><span class='hs-definition'>takeExtensions</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span>
|
|
<a name="line-297"></a><span class='hs-definition'>takeExtensions</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>snd</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitExtensions</span>
|
|
<a name="line-298"></a>
|
|
<a name="line-299"></a>
|
|
<a name="line-300"></a><a name="stripExtension"></a><span class='hs-comment'>-- | Drop the given extension from a FilePath, and the @\".\"@ preceding it.</span>
|
|
<a name="line-301"></a><span class='hs-comment'>-- Returns 'Nothing' if the FilePath does not have the given extension, or</span>
|
|
<a name="line-302"></a><span class='hs-comment'>-- 'Just' and the part before the extension if it does.</span>
|
|
<a name="line-303"></a><span class='hs-comment'>--</span>
|
|
<a name="line-304"></a><span class='hs-comment'>-- This function can be more predictable than 'dropExtensions',</span>
|
|
<a name="line-305"></a><span class='hs-comment'>-- especially if the filename might itself contain @.@ characters.</span>
|
|
<a name="line-306"></a><span class='hs-comment'>--</span>
|
|
<a name="line-307"></a><span class='hs-comment'>-- >>> stripExtension "hs.o" "foo.x.hs.o"</span>
|
|
<a name="line-308"></a><span class='hs-comment'>-- Just "foo.x"</span>
|
|
<a name="line-309"></a><span class='hs-comment'>-- >>> stripExtension "hi.o" "foo.x.hs.o"</span>
|
|
<a name="line-310"></a><span class='hs-comment'>-- Nothing</span>
|
|
<a name="line-311"></a><span class='hs-comment'>-- >>> stripExtension ".c.d" "a.b.c.d"</span>
|
|
<a name="line-312"></a><span class='hs-comment'>-- Just "a.b"</span>
|
|
<a name="line-313"></a><span class='hs-comment'>-- >>> stripExtension ".c.d" "a.b..c.d"</span>
|
|
<a name="line-314"></a><span class='hs-comment'>-- Just "a.b."</span>
|
|
<a name="line-315"></a><span class='hs-comment'>-- >>> stripExtension "baz" "foo.bar"</span>
|
|
<a name="line-316"></a><span class='hs-comment'>-- Nothing</span>
|
|
<a name="line-317"></a><span class='hs-comment'>-- >>> stripExtension "bar" "foobar"</span>
|
|
<a name="line-318"></a><span class='hs-comment'>-- Nothing</span>
|
|
<a name="line-319"></a><span class='hs-comment'>--</span>
|
|
<a name="line-320"></a><span class='hs-comment'>-- prop> \path -> stripExtension "" path == Just path</span>
|
|
<a name="line-321"></a><span class='hs-comment'>-- prop> \path -> dropExtension path == fromJust (stripExtension (takeExtension path) path)</span>
|
|
<a name="line-322"></a><span class='hs-comment'>-- prop> \path -> dropExtensions path == fromJust (stripExtension (takeExtensions path) path)</span>
|
|
<a name="line-323"></a><span class='hs-definition'>stripExtension</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Maybe</span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-324"></a><span class='hs-definition'>stripExtension</span> <span class='hs-varid'>bs</span> <span class='hs-varid'>path</span>
|
|
<a name="line-325"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Just</span> <span class='hs-varid'>path</span>
|
|
<a name="line-326"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>stripSuffix'</span> <span class='hs-varid'>dotExt</span> <span class='hs-varid'>path</span>
|
|
<a name="line-327"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-328"></a> <span class='hs-varid'>dotExt</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>isExtSeparator</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>head</span> <span class='hs-varid'>bs</span>
|
|
<a name="line-329"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>bs</span>
|
|
<a name="line-330"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>extSeparator</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>cons</span><span class='hs-varop'>`</span> <span class='hs-varid'>bs</span>
|
|
<a name="line-331"></a><span class='hs-cpp'>#if MIN_VERSION_bytestring(0,10,8)</span>
|
|
<a name="line-332"></a> <span class='hs-varid'>stripSuffix'</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>stripSuffix</span>
|
|
<a name="line-333"></a><span class='hs-cpp'>#else</span>
|
|
<a name="line-334"></a> <span class='hs-varid'>stripSuffix'</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>ys</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-varop'>.</span> <span class='hs-varid'>reverse</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>stripPrefix</span> <span class='hs-layout'>(</span><span class='hs-varid'>reverse</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>unpack</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>reverse</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>unpack</span> <span class='hs-varid'>ys</span><span class='hs-layout'>)</span>
|
|
<a name="line-335"></a><span class='hs-cpp'>#endif</span>
|
|
<a name="line-336"></a>
|
|
<a name="line-337"></a>
|
|
<a name="line-338"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-339"></a><span class='hs-comment'>-- Filename/directory functions</span>
|
|
<a name="line-340"></a>
|
|
<a name="line-341"></a>
|
|
<a name="line-342"></a><a name="splitFileName"></a><span class='hs-comment'>-- | Split a 'RawFilePath' into (path,file). 'combine' is the inverse</span>
|
|
<a name="line-343"></a><span class='hs-comment'>--</span>
|
|
<a name="line-344"></a><span class='hs-comment'>-- >>> splitFileName "path/file.txt"</span>
|
|
<a name="line-345"></a><span class='hs-comment'>-- ("path/","file.txt")</span>
|
|
<a name="line-346"></a><span class='hs-comment'>-- >>> splitFileName "path/"</span>
|
|
<a name="line-347"></a><span class='hs-comment'>-- ("path/","")</span>
|
|
<a name="line-348"></a><span class='hs-comment'>-- >>> splitFileName "file.txt"</span>
|
|
<a name="line-349"></a><span class='hs-comment'>-- ("./","file.txt")</span>
|
|
<a name="line-350"></a><span class='hs-comment'>--</span>
|
|
<a name="line-351"></a><span class='hs-comment'>-- prop> \path -> uncurry combine (splitFileName path) == path || fst (splitFileName path) == "./"</span>
|
|
<a name="line-352"></a><span class='hs-definition'>splitFileName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>RawFilePath</span><span class='hs-layout'>,</span> <span class='hs-conid'>RawFilePath</span><span class='hs-layout'>)</span>
|
|
<a name="line-353"></a><span class='hs-definition'>splitFileName</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>path</span>
|
|
<a name="line-354"></a> <span class='hs-keyword'>then</span> <span class='hs-layout'>(</span><span class='hs-varid'>dotSlash</span><span class='hs-layout'>,</span> <span class='hs-varid'>file</span><span class='hs-layout'>)</span>
|
|
<a name="line-355"></a> <span class='hs-keyword'>else</span> <span class='hs-layout'>(</span><span class='hs-varid'>path</span><span class='hs-layout'>,</span><span class='hs-varid'>file</span><span class='hs-layout'>)</span>
|
|
<a name="line-356"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-357"></a> <span class='hs-layout'>(</span><span class='hs-varid'>path</span><span class='hs-layout'>,</span><span class='hs-varid'>file</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitFileNameRaw</span> <span class='hs-varid'>x</span>
|
|
<a name="line-358"></a> <span class='hs-varid'>dotSlash</span> <span class='hs-keyglyph'>=</span> <span class='hs-sel'>_period</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>cons</span><span class='hs-varop'>`</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span><span class='hs-layout'>)</span>
|
|
<a name="line-359"></a>
|
|
<a name="line-360"></a>
|
|
<a name="line-361"></a><a name="takeFileName"></a><span class='hs-comment'>-- | Get the file name</span>
|
|
<a name="line-362"></a><span class='hs-comment'>--</span>
|
|
<a name="line-363"></a><span class='hs-comment'>-- >>> takeFileName "path/file.txt"</span>
|
|
<a name="line-364"></a><span class='hs-comment'>-- "file.txt"</span>
|
|
<a name="line-365"></a><span class='hs-comment'>-- >>> takeFileName "path/"</span>
|
|
<a name="line-366"></a><span class='hs-comment'>-- ""</span>
|
|
<a name="line-367"></a><span class='hs-definition'>takeFileName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-368"></a><span class='hs-definition'>takeFileName</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>snd</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitFileName</span>
|
|
<a name="line-369"></a>
|
|
<a name="line-370"></a>
|
|
<a name="line-371"></a><a name="replaceFileName"></a><span class='hs-comment'>-- | Change the file name</span>
|
|
<a name="line-372"></a><span class='hs-comment'>--</span>
|
|
<a name="line-373"></a><span class='hs-comment'>-- prop> \path -> replaceFileName path (takeFileName path) == path</span>
|
|
<a name="line-374"></a><span class='hs-definition'>replaceFileName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-375"></a><span class='hs-definition'>replaceFileName</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fst</span> <span class='hs-layout'>(</span><span class='hs-varid'>splitFileNameRaw</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varop'></></span> <span class='hs-varid'>y</span>
|
|
<a name="line-376"></a>
|
|
<a name="line-377"></a>
|
|
<a name="line-378"></a><a name="dropFileName"></a><span class='hs-comment'>-- | Drop the file name</span>
|
|
<a name="line-379"></a><span class='hs-comment'>--</span>
|
|
<a name="line-380"></a><span class='hs-comment'>-- >>> dropFileName "path/file.txt"</span>
|
|
<a name="line-381"></a><span class='hs-comment'>-- "path/"</span>
|
|
<a name="line-382"></a><span class='hs-comment'>-- >>> dropFileName "file.txt"</span>
|
|
<a name="line-383"></a><span class='hs-comment'>-- "./"</span>
|
|
<a name="line-384"></a><span class='hs-definition'>dropFileName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-385"></a><span class='hs-definition'>dropFileName</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fst</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitFileName</span>
|
|
<a name="line-386"></a>
|
|
<a name="line-387"></a>
|
|
<a name="line-388"></a><a name="takeBaseName"></a><span class='hs-comment'>-- | Get the file name, without a trailing extension</span>
|
|
<a name="line-389"></a><span class='hs-comment'>--</span>
|
|
<a name="line-390"></a><span class='hs-comment'>-- >>> takeBaseName "path/file.tar.gz"</span>
|
|
<a name="line-391"></a><span class='hs-comment'>-- "file.tar"</span>
|
|
<a name="line-392"></a><span class='hs-comment'>-- >>> takeBaseName ""</span>
|
|
<a name="line-393"></a><span class='hs-comment'>-- ""</span>
|
|
<a name="line-394"></a><span class='hs-definition'>takeBaseName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span>
|
|
<a name="line-395"></a><span class='hs-definition'>takeBaseName</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>dropExtension</span> <span class='hs-varop'>.</span> <span class='hs-varid'>takeFileName</span>
|
|
<a name="line-396"></a>
|
|
<a name="line-397"></a>
|
|
<a name="line-398"></a><a name="replaceBaseName"></a><span class='hs-comment'>-- | Change the base name</span>
|
|
<a name="line-399"></a><span class='hs-comment'>--</span>
|
|
<a name="line-400"></a><span class='hs-comment'>-- >>> replaceBaseName "path/file.tar.gz" "bob"</span>
|
|
<a name="line-401"></a><span class='hs-comment'>-- "path/bob.gz"</span>
|
|
<a name="line-402"></a><span class='hs-comment'>--</span>
|
|
<a name="line-403"></a><span class='hs-comment'>-- prop> \path -> replaceBaseName path (takeBaseName path) == path</span>
|
|
<a name="line-404"></a><span class='hs-definition'>replaceBaseName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-405"></a><span class='hs-definition'>replaceBaseName</span> <span class='hs-varid'>path</span> <span class='hs-varid'>name</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>combineRaw</span> <span class='hs-varid'>dir</span> <span class='hs-layout'>(</span><span class='hs-varid'>name</span> <span class='hs-varop'><.></span> <span class='hs-varid'>ext</span><span class='hs-layout'>)</span>
|
|
<a name="line-406"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-407"></a> <span class='hs-layout'>(</span><span class='hs-varid'>dir</span><span class='hs-layout'>,</span><span class='hs-varid'>file</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitFileNameRaw</span> <span class='hs-varid'>path</span>
|
|
<a name="line-408"></a> <span class='hs-varid'>ext</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>takeExtension</span> <span class='hs-varid'>file</span>
|
|
<a name="line-409"></a>
|
|
<a name="line-410"></a>
|
|
<a name="line-411"></a><a name="takeDirectory"></a><span class='hs-comment'>-- | Get the directory, moving up one level if it's already a directory</span>
|
|
<a name="line-412"></a><span class='hs-comment'>--</span>
|
|
<a name="line-413"></a><span class='hs-comment'>-- >>> takeDirectory "path/file.txt"</span>
|
|
<a name="line-414"></a><span class='hs-comment'>-- "path"</span>
|
|
<a name="line-415"></a><span class='hs-comment'>-- >>> takeDirectory "file"</span>
|
|
<a name="line-416"></a><span class='hs-comment'>-- "."</span>
|
|
<a name="line-417"></a><span class='hs-comment'>-- >>> takeDirectory "/path/to/"</span>
|
|
<a name="line-418"></a><span class='hs-comment'>-- "/path/to"</span>
|
|
<a name="line-419"></a><span class='hs-comment'>-- >>> takeDirectory "/path/to"</span>
|
|
<a name="line-420"></a><span class='hs-comment'>-- "/path"</span>
|
|
<a name="line-421"></a><span class='hs-definition'>takeDirectory</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-422"></a><span class='hs-definition'>takeDirectory</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-conid'>()</span> <span class='hs-keyword'>of</span>
|
|
<a name="line-423"></a> <span class='hs-conid'>()</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>x</span> <span class='hs-varop'>==</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>x</span>
|
|
<a name="line-424"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>res</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>file</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>file</span>
|
|
<a name="line-425"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>res</span>
|
|
<a name="line-426"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-427"></a> <span class='hs-varid'>res</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fst</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>spanEnd</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varid'>file</span>
|
|
<a name="line-428"></a> <span class='hs-varid'>file</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>dropFileName</span> <span class='hs-varid'>x</span>
|
|
<a name="line-429"></a>
|
|
<a name="line-430"></a>
|
|
<a name="line-431"></a><a name="replaceDirectory"></a><span class='hs-comment'>-- | Change the directory component of a 'RawFilePath'</span>
|
|
<a name="line-432"></a><span class='hs-comment'>--</span>
|
|
<a name="line-433"></a><span class='hs-comment'>-- prop> \path -> replaceDirectory path (takeDirectory path) `equalFilePath` path || takeDirectory path == "."</span>
|
|
<a name="line-434"></a><span class='hs-definition'>replaceDirectory</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-435"></a><span class='hs-definition'>replaceDirectory</span> <span class='hs-varid'>file</span> <span class='hs-varid'>dir</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>combineRaw</span> <span class='hs-varid'>dir</span> <span class='hs-layout'>(</span><span class='hs-varid'>takeFileName</span> <span class='hs-varid'>file</span><span class='hs-layout'>)</span>
|
|
<a name="line-436"></a>
|
|
<a name="line-437"></a>
|
|
<a name="line-438"></a><a name="combine"></a><span class='hs-comment'>-- | Join two paths together</span>
|
|
<a name="line-439"></a><span class='hs-comment'>--</span>
|
|
<a name="line-440"></a><span class='hs-comment'>-- >>> combine "/" "file"</span>
|
|
<a name="line-441"></a><span class='hs-comment'>-- "/file"</span>
|
|
<a name="line-442"></a><span class='hs-comment'>-- >>> combine "/path/to" "file"</span>
|
|
<a name="line-443"></a><span class='hs-comment'>-- "/path/to/file"</span>
|
|
<a name="line-444"></a><span class='hs-comment'>-- >>> combine "file" "/absolute/path"</span>
|
|
<a name="line-445"></a><span class='hs-comment'>-- "/absolute/path"</span>
|
|
<a name="line-446"></a><span class='hs-definition'>combine</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-447"></a><span class='hs-definition'>combine</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>head</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>b</span>
|
|
<a name="line-448"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>combineRaw</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
|
|
<a name="line-449"></a>
|
|
<a name="line-450"></a>
|
|
<a name="line-451"></a><a name="%3c/%3e"></a><span class='hs-comment'>-- | Operator version of combine</span>
|
|
<a name="line-452"></a><span class='hs-layout'>(</span><span class='hs-varop'></></span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-453"></a><span class='hs-layout'>(</span><span class='hs-varop'></></span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>combine</span>
|
|
<a name="line-454"></a>
|
|
<a name="line-455"></a><a name="splitPath"></a><span class='hs-comment'>-- | Split a path into a list of components:</span>
|
|
<a name="line-456"></a><span class='hs-comment'>--</span>
|
|
<a name="line-457"></a><span class='hs-comment'>-- >>> splitPath "/path/to/file.txt"</span>
|
|
<a name="line-458"></a><span class='hs-comment'>-- ["/","path/","to/","file.txt"]</span>
|
|
<a name="line-459"></a><span class='hs-comment'>--</span>
|
|
<a name="line-460"></a><span class='hs-comment'>-- prop> \path -> BS.concat (splitPath path) == path</span>
|
|
<a name="line-461"></a><span class='hs-definition'>splitPath</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>RawFilePath</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-462"></a><span class='hs-definition'>splitPath</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitter</span>
|
|
<a name="line-463"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-464"></a> <span class='hs-varid'>splitter</span> <span class='hs-varid'>x</span>
|
|
<a name="line-465"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>[]</span>
|
|
<a name="line-466"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>elemIndex</span> <span class='hs-varid'>pathSeparator</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>of</span>
|
|
<a name="line-467"></a> <span class='hs-conid'>Nothing</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-468"></a> <span class='hs-conid'>Just</span> <span class='hs-varid'>ix</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>case</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>findIndex</span> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>isPathSeparator</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>drop</span> <span class='hs-layout'>(</span><span class='hs-varid'>ix</span><span class='hs-varop'>+</span><span class='hs-num'>1</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>of</span>
|
|
<a name="line-469"></a> <span class='hs-conid'>Nothing</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-470"></a> <span class='hs-conid'>Just</span> <span class='hs-varid'>runlen</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>uncurry</span> <span class='hs-layout'>(</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>second</span> <span class='hs-varid'>splitter</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>splitAt</span> <span class='hs-layout'>(</span><span class='hs-varid'>ix</span><span class='hs-varop'>+</span><span class='hs-num'>1</span><span class='hs-varop'>+</span><span class='hs-varid'>runlen</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
|
|
<a name="line-471"></a>
|
|
<a name="line-472"></a>
|
|
<a name="line-473"></a><a name="joinPath"></a><span class='hs-comment'>-- | Join a split path back together</span>
|
|
<a name="line-474"></a><span class='hs-comment'>--</span>
|
|
<a name="line-475"></a><span class='hs-comment'>-- prop> \path -> joinPath (splitPath path) == path</span>
|
|
<a name="line-476"></a><span class='hs-comment'>--</span>
|
|
<a name="line-477"></a><span class='hs-comment'>-- >>> joinPath ["path","to","file.txt"]</span>
|
|
<a name="line-478"></a><span class='hs-comment'>-- "path/to/file.txt"</span>
|
|
<a name="line-479"></a><span class='hs-definition'>joinPath</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>RawFilePath</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-480"></a><span class='hs-definition'>joinPath</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>foldr</span> <span class='hs-layout'>(</span><span class='hs-varop'></></span><span class='hs-layout'>)</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>empty</span>
|
|
<a name="line-481"></a>
|
|
<a name="line-482"></a>
|
|
<a name="line-483"></a><a name="splitDirectories"></a><span class='hs-comment'>-- | Like 'splitPath', but without trailing slashes</span>
|
|
<a name="line-484"></a><span class='hs-comment'>--</span>
|
|
<a name="line-485"></a><span class='hs-comment'>-- >>> splitDirectories "/path/to/file.txt"</span>
|
|
<a name="line-486"></a><span class='hs-comment'>-- ["/","path","to","file.txt"]</span>
|
|
<a name="line-487"></a><span class='hs-comment'>-- >>> splitDirectories ""</span>
|
|
<a name="line-488"></a><span class='hs-comment'>-- []</span>
|
|
<a name="line-489"></a><span class='hs-definition'>splitDirectories</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>RawFilePath</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-490"></a><span class='hs-definition'>splitDirectories</span> <span class='hs-varid'>x</span>
|
|
<a name="line-491"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>[]</span>
|
|
<a name="line-492"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>head</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>root</span><span class='hs-layout'>,</span><span class='hs-varid'>rest</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>splitAt</span> <span class='hs-num'>1</span> <span class='hs-varid'>x</span>
|
|
<a name="line-493"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>root</span> <span class='hs-conop'>:</span> <span class='hs-varid'>splitter</span> <span class='hs-varid'>rest</span>
|
|
<a name="line-494"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitter</span> <span class='hs-varid'>x</span>
|
|
<a name="line-495"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-496"></a> <span class='hs-varid'>splitter</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>filter</span> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>split</span> <span class='hs-varid'>pathSeparator</span>
|
|
<a name="line-497"></a>
|
|
<a name="line-498"></a>
|
|
<a name="line-499"></a>
|
|
<a name="line-500"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-501"></a><span class='hs-comment'>-- Trailing slash functions</span>
|
|
<a name="line-502"></a>
|
|
<a name="line-503"></a><a name="hasTrailingPathSeparator"></a><span class='hs-comment'>-- | Check if the last character of a 'RawFilePath' is '/'.</span>
|
|
<a name="line-504"></a><span class='hs-comment'>--</span>
|
|
<a name="line-505"></a><span class='hs-comment'>-- >>> hasTrailingPathSeparator "/path/"</span>
|
|
<a name="line-506"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-507"></a><span class='hs-comment'>-- >>> hasTrailingPathSeparator "/"</span>
|
|
<a name="line-508"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-509"></a><span class='hs-comment'>-- >>> hasTrailingPathSeparator "/path"</span>
|
|
<a name="line-510"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-511"></a><span class='hs-definition'>hasTrailingPathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-512"></a><span class='hs-definition'>hasTrailingPathSeparator</span> <span class='hs-varid'>x</span>
|
|
<a name="line-513"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
|
|
<a name="line-514"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>last</span> <span class='hs-varid'>x</span>
|
|
<a name="line-515"></a>
|
|
<a name="line-516"></a>
|
|
<a name="line-517"></a><a name="addTrailingPathSeparator"></a><span class='hs-comment'>-- | Add a trailing path separator.</span>
|
|
<a name="line-518"></a><span class='hs-comment'>--</span>
|
|
<a name="line-519"></a><span class='hs-comment'>-- >>> addTrailingPathSeparator "/path"</span>
|
|
<a name="line-520"></a><span class='hs-comment'>-- "/path/"</span>
|
|
<a name="line-521"></a><span class='hs-comment'>-- >>> addTrailingPathSeparator "/path/"</span>
|
|
<a name="line-522"></a><span class='hs-comment'>-- "/path/"</span>
|
|
<a name="line-523"></a><span class='hs-comment'>-- >>> addTrailingPathSeparator "/"</span>
|
|
<a name="line-524"></a><span class='hs-comment'>-- "/"</span>
|
|
<a name="line-525"></a><span class='hs-definition'>addTrailingPathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-526"></a><span class='hs-definition'>addTrailingPathSeparator</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>hasTrailingPathSeparator</span> <span class='hs-varid'>x</span>
|
|
<a name="line-527"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>x</span>
|
|
<a name="line-528"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>x</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>snoc</span><span class='hs-varop'>`</span> <span class='hs-varid'>pathSeparator</span>
|
|
<a name="line-529"></a>
|
|
<a name="line-530"></a>
|
|
<a name="line-531"></a><a name="dropTrailingPathSeparator"></a><span class='hs-comment'>-- | Remove a trailing path separator</span>
|
|
<a name="line-532"></a><span class='hs-comment'>--</span>
|
|
<a name="line-533"></a><span class='hs-comment'>-- >>> dropTrailingPathSeparator "/path/"</span>
|
|
<a name="line-534"></a><span class='hs-comment'>-- "/path"</span>
|
|
<a name="line-535"></a><span class='hs-comment'>-- >>> dropTrailingPathSeparator "/path////"</span>
|
|
<a name="line-536"></a><span class='hs-comment'>-- "/path"</span>
|
|
<a name="line-537"></a><span class='hs-comment'>-- >>> dropTrailingPathSeparator "/"</span>
|
|
<a name="line-538"></a><span class='hs-comment'>-- "/"</span>
|
|
<a name="line-539"></a><span class='hs-comment'>-- >>> dropTrailingPathSeparator "//"</span>
|
|
<a name="line-540"></a><span class='hs-comment'>-- "/"</span>
|
|
<a name="line-541"></a><span class='hs-definition'>dropTrailingPathSeparator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-542"></a><span class='hs-definition'>dropTrailingPathSeparator</span> <span class='hs-varid'>x</span>
|
|
<a name="line-543"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>x</span> <span class='hs-varop'>==</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span>
|
|
<a name="line-544"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>hasTrailingPathSeparator</span> <span class='hs-varid'>x</span>
|
|
<a name="line-545"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>dropTrailingPathSeparator</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>init</span> <span class='hs-varid'>x</span>
|
|
<a name="line-546"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>x</span>
|
|
<a name="line-547"></a>
|
|
<a name="line-548"></a>
|
|
<a name="line-549"></a>
|
|
<a name="line-550"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-551"></a><span class='hs-comment'>-- File name manipulations</span>
|
|
<a name="line-552"></a>
|
|
<a name="line-553"></a>
|
|
<a name="line-554"></a><a name="normalise"></a><span class='hs-comment'>-- |Normalise a file.</span>
|
|
<a name="line-555"></a><span class='hs-comment'>--</span>
|
|
<a name="line-556"></a><span class='hs-comment'>-- >>> normalise "/file/\\test////"</span>
|
|
<a name="line-557"></a><span class='hs-comment'>-- "/file/\\test/"</span>
|
|
<a name="line-558"></a><span class='hs-comment'>-- >>> normalise "/file/./test"</span>
|
|
<a name="line-559"></a><span class='hs-comment'>-- "/file/test"</span>
|
|
<a name="line-560"></a><span class='hs-comment'>-- >>> normalise "/test/file/../bob/fred/"</span>
|
|
<a name="line-561"></a><span class='hs-comment'>-- "/test/file/../bob/fred/"</span>
|
|
<a name="line-562"></a><span class='hs-comment'>-- >>> normalise "../bob/fred/"</span>
|
|
<a name="line-563"></a><span class='hs-comment'>-- "../bob/fred/"</span>
|
|
<a name="line-564"></a><span class='hs-comment'>-- >>> normalise "./bob/fred/"</span>
|
|
<a name="line-565"></a><span class='hs-comment'>-- "bob/fred/"</span>
|
|
<a name="line-566"></a><span class='hs-comment'>-- >>> normalise "./bob////.fred/./...///./..///#."</span>
|
|
<a name="line-567"></a><span class='hs-comment'>-- "bob/.fred/.../../#."</span>
|
|
<a name="line-568"></a><span class='hs-comment'>-- >>> normalise "."</span>
|
|
<a name="line-569"></a><span class='hs-comment'>-- "."</span>
|
|
<a name="line-570"></a><span class='hs-comment'>-- >>> normalise "./"</span>
|
|
<a name="line-571"></a><span class='hs-comment'>-- "./"</span>
|
|
<a name="line-572"></a><span class='hs-comment'>-- >>> normalise "./."</span>
|
|
<a name="line-573"></a><span class='hs-comment'>-- "./"</span>
|
|
<a name="line-574"></a><span class='hs-comment'>-- >>> normalise "/./"</span>
|
|
<a name="line-575"></a><span class='hs-comment'>-- "/"</span>
|
|
<a name="line-576"></a><span class='hs-comment'>-- >>> normalise "/"</span>
|
|
<a name="line-577"></a><span class='hs-comment'>-- "/"</span>
|
|
<a name="line-578"></a><span class='hs-comment'>-- >>> normalise "bob/fred/."</span>
|
|
<a name="line-579"></a><span class='hs-comment'>-- "bob/fred/"</span>
|
|
<a name="line-580"></a><span class='hs-comment'>-- >>> normalise "//home"</span>
|
|
<a name="line-581"></a><span class='hs-comment'>-- "/home"</span>
|
|
<a name="line-582"></a><span class='hs-definition'>normalise</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-583"></a><span class='hs-definition'>normalise</span> <span class='hs-varid'>filepath</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-584"></a> <span class='hs-varid'>result</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span><span class='hs-varop'>`</span>
|
|
<a name="line-585"></a> <span class='hs-layout'>(</span><span class='hs-keyword'>if</span> <span class='hs-varid'>addPathSeparator</span>
|
|
<a name="line-586"></a> <span class='hs-keyword'>then</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span>
|
|
<a name="line-587"></a> <span class='hs-keyword'>else</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>empty</span><span class='hs-layout'>)</span>
|
|
<a name="line-588"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-589"></a> <span class='hs-varid'>result</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>filepath</span>
|
|
<a name="line-590"></a> <span class='hs-keyword'>in</span> <span class='hs-keyword'>if</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>n</span>
|
|
<a name="line-591"></a> <span class='hs-keyword'>then</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-sel'>_period</span>
|
|
<a name="line-592"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>n</span>
|
|
<a name="line-593"></a> <span class='hs-varid'>addPathSeparator</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>isDirPath</span> <span class='hs-varid'>filepath</span> <span class='hs-varop'>&&</span>
|
|
<a name="line-594"></a> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-varid'>hasTrailingPathSeparator</span> <span class='hs-varid'>result</span><span class='hs-layout'>)</span>
|
|
<a name="line-595"></a> <span class='hs-varid'>isDirPath</span> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hasTrailingPathSeparator</span> <span class='hs-varid'>xs</span>
|
|
<a name="line-596"></a> <span class='hs-varop'>||</span> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-varop'>&&</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>last</span> <span class='hs-varid'>xs</span> <span class='hs-varop'>==</span> <span class='hs-sel'>_period</span>
|
|
<a name="line-597"></a> <span class='hs-varop'>&&</span> <span class='hs-varid'>hasTrailingPathSeparator</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>init</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span>
|
|
<a name="line-598"></a> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>joinPath</span> <span class='hs-varop'>.</span> <span class='hs-varid'>dropDots</span> <span class='hs-varop'>.</span> <span class='hs-varid'>propSep</span> <span class='hs-varop'>.</span> <span class='hs-varid'>splitDirectories</span>
|
|
<a name="line-599"></a> <span class='hs-varid'>propSep</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-600"></a> <span class='hs-varid'>propSep</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span>
|
|
<a name="line-601"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>all</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-varid'>pathSeparator</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span> <span class='hs-conop'>:</span> <span class='hs-varid'>xs</span>
|
|
<a name="line-602"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span> <span class='hs-conop'>:</span> <span class='hs-varid'>xs</span>
|
|
<a name="line-603"></a> <span class='hs-varid'>propSep</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>[]</span>
|
|
<a name="line-604"></a> <span class='hs-varid'>dropDots</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ByteString</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-605"></a> <span class='hs-varid'>dropDots</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>filter</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-sel'>_period</span> <span class='hs-varop'>/=</span><span class='hs-layout'>)</span>
|
|
<a name="line-606"></a>
|
|
<a name="line-607"></a>
|
|
<a name="line-608"></a>
|
|
<a name="line-609"></a><a name="makeRelative"></a><span class='hs-comment'>-- | Contract a filename, based on a relative path. Note that the resulting</span>
|
|
<a name="line-610"></a><span class='hs-comment'>-- path will never introduce @..@ paths, as the presence of symlinks</span>
|
|
<a name="line-611"></a><span class='hs-comment'>-- means @..\/b@ may not reach @a\/b@ if it starts from @a\/c@. For a</span>
|
|
<a name="line-612"></a><span class='hs-comment'>-- worked example see</span>
|
|
<a name="line-613"></a><span class='hs-comment'>-- <<a href="http://neilmitchell.blogspot.co.uk/2015/10/filepaths-are-subtle-symlinks-are-hard.html">http://neilmitchell.blogspot.co.uk/2015/10/filepaths-are-subtle-symlinks-are-hard.html</a> this blog post>.</span>
|
|
<a name="line-614"></a><span class='hs-comment'>--</span>
|
|
<a name="line-615"></a><span class='hs-comment'>-- >>> makeRelative "/directory" "/directory/file.ext"</span>
|
|
<a name="line-616"></a><span class='hs-comment'>-- "file.ext"</span>
|
|
<a name="line-617"></a><span class='hs-comment'>-- >>> makeRelative "/Home" "/home/bob"</span>
|
|
<a name="line-618"></a><span class='hs-comment'>-- "/home/bob"</span>
|
|
<a name="line-619"></a><span class='hs-comment'>-- >>> makeRelative "/home/" "/home/bob/foo/bar"</span>
|
|
<a name="line-620"></a><span class='hs-comment'>-- "bob/foo/bar"</span>
|
|
<a name="line-621"></a><span class='hs-comment'>-- >>> makeRelative "/fred" "bob"</span>
|
|
<a name="line-622"></a><span class='hs-comment'>-- "bob"</span>
|
|
<a name="line-623"></a><span class='hs-comment'>-- >>> makeRelative "/file/test" "/file/test/fred"</span>
|
|
<a name="line-624"></a><span class='hs-comment'>-- "fred"</span>
|
|
<a name="line-625"></a><span class='hs-comment'>-- >>> makeRelative "/file/test" "/file/test/fred/"</span>
|
|
<a name="line-626"></a><span class='hs-comment'>-- "fred/"</span>
|
|
<a name="line-627"></a><span class='hs-comment'>-- >>> makeRelative "some/path" "some/path/a/b/c"</span>
|
|
<a name="line-628"></a><span class='hs-comment'>-- "a/b/c"</span>
|
|
<a name="line-629"></a><span class='hs-comment'>--</span>
|
|
<a name="line-630"></a><span class='hs-comment'>-- prop> \p -> makeRelative p p == "."</span>
|
|
<a name="line-631"></a><span class='hs-comment'>-- prop> \p -> makeRelative (takeDirectory p) p `equalFilePath` takeFileName p</span>
|
|
<a name="line-632"></a><span class='hs-comment'>-- prop \x y -> equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x</span>
|
|
<a name="line-633"></a><span class='hs-definition'>makeRelative</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-634"></a><span class='hs-definition'>makeRelative</span> <span class='hs-varid'>root</span> <span class='hs-varid'>path</span>
|
|
<a name="line-635"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>equalFilePath</span> <span class='hs-varid'>root</span> <span class='hs-varid'>path</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-sel'>_period</span>
|
|
<a name="line-636"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>takeAbs</span> <span class='hs-varid'>root</span> <span class='hs-varop'>/=</span> <span class='hs-varid'>takeAbs</span> <span class='hs-varid'>path</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>path</span>
|
|
<a name="line-637"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>dropAbs</span> <span class='hs-varid'>root</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>dropAbs</span> <span class='hs-varid'>path</span><span class='hs-layout'>)</span>
|
|
<a name="line-638"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-639"></a> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span>
|
|
<a name="line-640"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>dropWhile</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varid'>y</span>
|
|
<a name="line-641"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>x1</span><span class='hs-layout'>,</span><span class='hs-varid'>x2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>g</span> <span class='hs-varid'>x</span>
|
|
<a name="line-642"></a> <span class='hs-layout'>(</span><span class='hs-varid'>y1</span><span class='hs-layout'>,</span><span class='hs-varid'>y2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>g</span> <span class='hs-varid'>y</span>
|
|
<a name="line-643"></a> <span class='hs-keyword'>in</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>equalFilePath</span> <span class='hs-varid'>x1</span> <span class='hs-varid'>y1</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>f</span> <span class='hs-varid'>x2</span> <span class='hs-varid'>y2</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>path</span>
|
|
<a name="line-644"></a> <span class='hs-varid'>g</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>dropWhile</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>dropWhile</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span>
|
|
<a name="line-645"></a> <span class='hs-keyword'>where</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>break</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>dropWhile</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-varid'>x</span>
|
|
<a name="line-646"></a> <span class='hs-varid'>dropAbs</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>snd</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>span</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-sel'>_slash</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
|
|
<a name="line-647"></a> <span class='hs-varid'>takeAbs</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fst</span> <span class='hs-varop'>$</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>span</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-sel'>_slash</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
|
|
<a name="line-648"></a>
|
|
<a name="line-649"></a>
|
|
<a name="line-650"></a><a name="equalFilePath"></a><span class='hs-comment'>-- |Equality of two filepaths. The filepaths are normalised</span>
|
|
<a name="line-651"></a><span class='hs-comment'>-- and trailing path separators are dropped.</span>
|
|
<a name="line-652"></a><span class='hs-comment'>--</span>
|
|
<a name="line-653"></a><span class='hs-comment'>-- >>> equalFilePath "foo" "foo"</span>
|
|
<a name="line-654"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-655"></a><span class='hs-comment'>-- >>> equalFilePath "foo" "foo/"</span>
|
|
<a name="line-656"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-657"></a><span class='hs-comment'>-- >>> equalFilePath "foo" "./foo"</span>
|
|
<a name="line-658"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-659"></a><span class='hs-comment'>-- >>> equalFilePath "" ""</span>
|
|
<a name="line-660"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-661"></a><span class='hs-comment'>-- >>> equalFilePath "foo" "/foo"</span>
|
|
<a name="line-662"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-663"></a><span class='hs-comment'>-- >>> equalFilePath "foo" "FOO"</span>
|
|
<a name="line-664"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-665"></a><span class='hs-comment'>-- >>> equalFilePath "foo" "../foo"</span>
|
|
<a name="line-666"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-667"></a><span class='hs-comment'>--</span>
|
|
<a name="line-668"></a><span class='hs-comment'>-- prop> \p -> equalFilePath p p</span>
|
|
<a name="line-669"></a><span class='hs-definition'>equalFilePath</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-670"></a><span class='hs-definition'>equalFilePath</span> <span class='hs-varid'>p1</span> <span class='hs-varid'>p2</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>p1</span> <span class='hs-varop'>==</span> <span class='hs-varid'>f</span> <span class='hs-varid'>p2</span>
|
|
<a name="line-671"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-672"></a> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>dropTrailingPathSeparator</span> <span class='hs-varop'>$</span> <span class='hs-varid'>normalise</span> <span class='hs-varid'>x</span>
|
|
<a name="line-673"></a>
|
|
<a name="line-674"></a>
|
|
<a name="line-675"></a><a name="isRelative"></a><span class='hs-comment'>-- | Check if a path is relative</span>
|
|
<a name="line-676"></a><span class='hs-comment'>--</span>
|
|
<a name="line-677"></a><span class='hs-comment'>-- prop> \path -> isRelative path /= isAbsolute path</span>
|
|
<a name="line-678"></a><span class='hs-definition'>isRelative</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-679"></a><span class='hs-definition'>isRelative</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>isAbsolute</span>
|
|
<a name="line-680"></a>
|
|
<a name="line-681"></a>
|
|
<a name="line-682"></a><a name="isAbsolute"></a><span class='hs-comment'>-- | Check if a path is absolute</span>
|
|
<a name="line-683"></a><span class='hs-comment'>--</span>
|
|
<a name="line-684"></a><span class='hs-comment'>-- >>> isAbsolute "/path"</span>
|
|
<a name="line-685"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-686"></a><span class='hs-comment'>-- >>> isAbsolute "path"</span>
|
|
<a name="line-687"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-688"></a><span class='hs-comment'>-- >>> isAbsolute ""</span>
|
|
<a name="line-689"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-690"></a><span class='hs-definition'>isAbsolute</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-691"></a><span class='hs-definition'>isAbsolute</span> <span class='hs-varid'>x</span>
|
|
<a name="line-692"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>length</span> <span class='hs-varid'>x</span> <span class='hs-varop'>></span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>head</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
|
|
<a name="line-693"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
|
|
<a name="line-694"></a>
|
|
<a name="line-695"></a>
|
|
<a name="line-696"></a><a name="isValid"></a><span class='hs-comment'>-- | Is a FilePath valid, i.e. could you create a file like it?</span>
|
|
<a name="line-697"></a><span class='hs-comment'>--</span>
|
|
<a name="line-698"></a><span class='hs-comment'>-- >>> isValid ""</span>
|
|
<a name="line-699"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-700"></a><span class='hs-comment'>-- >>> isValid "\0"</span>
|
|
<a name="line-701"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-702"></a><span class='hs-comment'>-- >>> isValid "/random_ path:*"</span>
|
|
<a name="line-703"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-704"></a><span class='hs-definition'>isValid</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-705"></a><span class='hs-definition'>isValid</span> <span class='hs-varid'>filepath</span>
|
|
<a name="line-706"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>filepath</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
|
|
<a name="line-707"></a> <span class='hs-keyglyph'>|</span> <span class='hs-sel'>_nul</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>elem</span><span class='hs-varop'>`</span> <span class='hs-varid'>filepath</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
|
|
<a name="line-708"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>True</span>
|
|
<a name="line-709"></a>
|
|
<a name="line-710"></a>
|
|
<a name="line-711"></a><a name="makeValid"></a><span class='hs-comment'>-- | Take a FilePath and make it valid; does not change already valid FilePaths.</span>
|
|
<a name="line-712"></a><span class='hs-comment'>--</span>
|
|
<a name="line-713"></a><span class='hs-comment'>-- >>> makeValid ""</span>
|
|
<a name="line-714"></a><span class='hs-comment'>-- "_"</span>
|
|
<a name="line-715"></a><span class='hs-comment'>-- >>> makeValid "file\0name"</span>
|
|
<a name="line-716"></a><span class='hs-comment'>-- "file_name"</span>
|
|
<a name="line-717"></a><span class='hs-comment'>--</span>
|
|
<a name="line-718"></a><span class='hs-comment'>-- prop> \p -> if isValid p then makeValid p == p else makeValid p /= p</span>
|
|
<a name="line-719"></a><span class='hs-comment'>-- prop> \p -> isValid (makeValid p)</span>
|
|
<a name="line-720"></a><span class='hs-definition'>makeValid</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-721"></a><span class='hs-definition'>makeValid</span> <span class='hs-varid'>path</span>
|
|
<a name="line-722"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>path</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-sel'>_underscore</span>
|
|
<a name="line-723"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>map</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>x</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>if</span> <span class='hs-varid'>x</span> <span class='hs-varop'>==</span> <span class='hs-sel'>_nul</span> <span class='hs-keyword'>then</span> <span class='hs-sel'>_underscore</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>path</span>
|
|
<a name="line-724"></a>
|
|
<a name="line-725"></a>
|
|
<a name="line-726"></a><a name="isFileName"></a><span class='hs-comment'>-- | Is the given path a valid filename? This includes</span>
|
|
<a name="line-727"></a><span class='hs-comment'>-- "." and "..".</span>
|
|
<a name="line-728"></a><span class='hs-comment'>--</span>
|
|
<a name="line-729"></a><span class='hs-comment'>-- >>> isFileName "lal"</span>
|
|
<a name="line-730"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-731"></a><span class='hs-comment'>-- >>> isFileName "."</span>
|
|
<a name="line-732"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-733"></a><span class='hs-comment'>-- >>> isFileName ".."</span>
|
|
<a name="line-734"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-735"></a><span class='hs-comment'>-- >>> isFileName ""</span>
|
|
<a name="line-736"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-737"></a><span class='hs-comment'>-- >>> isFileName "\0"</span>
|
|
<a name="line-738"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-739"></a><span class='hs-comment'>-- >>> isFileName "/random_ path:*"</span>
|
|
<a name="line-740"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-741"></a><span class='hs-definition'>isFileName</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-742"></a><span class='hs-definition'>isFileName</span> <span class='hs-varid'>filepath</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-743"></a> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>isInfixOf</span><span class='hs-varop'>`</span> <span class='hs-varid'>filepath</span><span class='hs-layout'>)</span> <span class='hs-varop'>&&</span>
|
|
<a name="line-744"></a> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>filepath</span><span class='hs-layout'>)</span> <span class='hs-varop'>&&</span>
|
|
<a name="line-745"></a> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-sel'>_nul</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>elem</span><span class='hs-varop'>`</span> <span class='hs-varid'>filepath</span><span class='hs-layout'>)</span>
|
|
<a name="line-746"></a>
|
|
<a name="line-747"></a>
|
|
<a name="line-748"></a><a name="hasParentDir"></a><span class='hs-comment'>-- | Check if the filepath has any parent directories in it.</span>
|
|
<a name="line-749"></a><span class='hs-comment'>--</span>
|
|
<a name="line-750"></a><span class='hs-comment'>-- >>> hasParentDir "/.."</span>
|
|
<a name="line-751"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-752"></a><span class='hs-comment'>-- >>> hasParentDir "foo/bar/.."</span>
|
|
<a name="line-753"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-754"></a><span class='hs-comment'>-- >>> hasParentDir "foo/../bar/."</span>
|
|
<a name="line-755"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-756"></a><span class='hs-comment'>-- >>> hasParentDir "foo/bar"</span>
|
|
<a name="line-757"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-758"></a><span class='hs-comment'>-- >>> hasParentDir "foo"</span>
|
|
<a name="line-759"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-760"></a><span class='hs-comment'>-- >>> hasParentDir ""</span>
|
|
<a name="line-761"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-762"></a><span class='hs-comment'>-- >>> hasParentDir ".."</span>
|
|
<a name="line-763"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-764"></a><span class='hs-definition'>hasParentDir</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-765"></a><span class='hs-definition'>hasParentDir</span> <span class='hs-varid'>filepath</span> <span class='hs-keyglyph'>=</span>
|
|
<a name="line-766"></a> <span class='hs-layout'>(</span><span class='hs-varid'>pathSeparator</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>cons</span><span class='hs-varop'>`</span> <span class='hs-varid'>pathDoubleDot</span><span class='hs-layout'>)</span>
|
|
<a name="line-767"></a> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>isSuffixOf</span><span class='hs-varop'>`</span> <span class='hs-varid'>filepath</span>
|
|
<a name="line-768"></a> <span class='hs-varop'>||</span>
|
|
<a name="line-769"></a> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span>
|
|
<a name="line-770"></a> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span><span class='hs-varop'>`</span> <span class='hs-varid'>pathDoubleDot</span>
|
|
<a name="line-771"></a> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span><span class='hs-varop'>`</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span><span class='hs-layout'>)</span>
|
|
<a name="line-772"></a> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>isInfixOf</span><span class='hs-varop'>`</span> <span class='hs-varid'>filepath</span>
|
|
<a name="line-773"></a> <span class='hs-varop'>||</span>
|
|
<a name="line-774"></a> <span class='hs-layout'>(</span><span class='hs-varid'>pathDoubleDot</span> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span><span class='hs-varop'>`</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span><span class='hs-layout'>)</span>
|
|
<a name="line-775"></a> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>isPrefixOf</span><span class='hs-varop'>`</span> <span class='hs-varid'>filepath</span>
|
|
<a name="line-776"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-777"></a> <span class='hs-varid'>pathDoubleDot</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-keyglyph'>[</span><span class='hs-sel'>_period</span><span class='hs-layout'>,</span> <span class='hs-sel'>_period</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-778"></a>
|
|
<a name="line-779"></a>
|
|
<a name="line-780"></a><a name="hiddenFile"></a><span class='hs-comment'>-- | Whether the file is a hidden file.</span>
|
|
<a name="line-781"></a><span class='hs-comment'>--</span>
|
|
<a name="line-782"></a><span class='hs-comment'>-- >>> hiddenFile ".foo"</span>
|
|
<a name="line-783"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-784"></a><span class='hs-comment'>-- >>> hiddenFile "..foo.bar"</span>
|
|
<a name="line-785"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-786"></a><span class='hs-comment'>-- >>> hiddenFile "some/path/.bar"</span>
|
|
<a name="line-787"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-788"></a><span class='hs-comment'>-- >>> hiddenFile "..."</span>
|
|
<a name="line-789"></a><span class='hs-comment'>-- True</span>
|
|
<a name="line-790"></a><span class='hs-comment'>-- >>> hiddenFile "dod.bar"</span>
|
|
<a name="line-791"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-792"></a><span class='hs-comment'>-- >>> hiddenFile "."</span>
|
|
<a name="line-793"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-794"></a><span class='hs-comment'>-- >>> hiddenFile ".."</span>
|
|
<a name="line-795"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-796"></a><span class='hs-comment'>-- >>> hiddenFile ""</span>
|
|
<a name="line-797"></a><span class='hs-comment'>-- False</span>
|
|
<a name="line-798"></a><span class='hs-definition'>hiddenFile</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
|
|
<a name="line-799"></a><span class='hs-definition'>hiddenFile</span> <span class='hs-varid'>fp</span>
|
|
<a name="line-800"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>fn</span> <span class='hs-varop'>==</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-keyglyph'>[</span><span class='hs-sel'>_period</span><span class='hs-layout'>,</span> <span class='hs-sel'>_period</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
|
|
<a name="line-801"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>fn</span> <span class='hs-varop'>==</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-keyglyph'>[</span><span class='hs-sel'>_period</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
|
|
<a name="line-802"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>pack</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>extSeparator</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-803"></a> <span class='hs-varop'>`</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>isPrefixOf</span><span class='hs-varop'>`</span> <span class='hs-varid'>fn</span>
|
|
<a name="line-804"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-805"></a> <span class='hs-varid'>fn</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>takeFileName</span> <span class='hs-varid'>fp</span>
|
|
<a name="line-806"></a>
|
|
<a name="line-807"></a>
|
|
<a name="line-808"></a>
|
|
<a name="line-809"></a><span class='hs-comment'>------------------------</span>
|
|
<a name="line-810"></a><span class='hs-comment'>-- internal stuff</span>
|
|
<a name="line-811"></a>
|
|
<a name="line-812"></a><a name="splitFileNameRaw"></a><span class='hs-comment'>-- Just split the input FileName without adding/normalizing or changing</span>
|
|
<a name="line-813"></a><span class='hs-comment'>-- anything.</span>
|
|
<a name="line-814"></a><span class='hs-definition'>splitFileNameRaw</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>RawFilePath</span><span class='hs-layout'>,</span> <span class='hs-conid'>RawFilePath</span><span class='hs-layout'>)</span>
|
|
<a name="line-815"></a><span class='hs-definition'>splitFileNameRaw</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>breakEnd</span> <span class='hs-varid'>isPathSeparator</span>
|
|
<a name="line-816"></a>
|
|
<a name="line-817"></a><a name="combineRaw"></a><span class='hs-comment'>-- | Combine two paths, assuming rhs is NOT absolute.</span>
|
|
<a name="line-818"></a><span class='hs-definition'>combineRaw</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>RawFilePath</span>
|
|
<a name="line-819"></a><span class='hs-definition'>combineRaw</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>b</span>
|
|
<a name="line-820"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>null</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>a</span>
|
|
<a name="line-821"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>isPathSeparator</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>last</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>append</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
|
|
<a name="line-822"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>intercalate</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>singleton</span> <span class='hs-varid'>pathSeparator</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span>
|
|
<a name="line-823"></a>
|
|
</pre></body>
|
|
</html>
|