adeiu, MissingH

Removed dependency on MissingH, instead depending on the split
library.

After laying groundwork for this since 2015, it
was mostly straightforward. Added Utility.Tuple and
Utility.Split. Eyeballed System.Path.WildMatch while implementing
the same thing.

Since MissingH's progress meter display was being used, I re-implemented
my own. Bonus: Now progress is displayed for transfers of files of
unknown size.

This commit was sponsored by Shane-o on Patreon.
This commit is contained in:
Joey Hess 2017-05-15 23:32:17 -04:00
parent 6dd806f1ad
commit a1730cd6af
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
37 changed files with 230 additions and 101 deletions

View file

@ -10,7 +10,6 @@
module Utility.Path where
import Data.String.Utils
import System.FilePath
import Data.List
import Data.Maybe
@ -28,6 +27,7 @@ import Utility.Exception
import Utility.Monad
import Utility.UserInfo
import Utility.Directory
import Utility.Split
{- Simplifies a path, removing any "." component, collapsing "dir/..",
- and removing the trailing path separator.
@ -76,12 +76,13 @@ parentDir = takeDirectory . dropTrailingPathSeparator
upFrom :: FilePath -> Maybe FilePath
upFrom dir
| length dirs < 2 = Nothing
| otherwise = Just $ joinDrive drive (intercalate s $ init dirs)
| otherwise = Just $ joinDrive drive $ intercalate s $ init dirs
where
-- on Unix, the drive will be "/" when the dir is absolute, otherwise ""
-- on Unix, the drive will be "/" when the dir is absolute,
-- otherwise ""
(drive, path) = splitDrive dir
dirs = filter (not . null) $ split s path
s = [pathSeparator]
dirs = filter (not . null) $ split s path
prop_upFrom_basics :: FilePath -> Bool
prop_upFrom_basics dir
@ -140,9 +141,9 @@ relPathDirToFileAbs from to
where
pfrom = sp from
pto = sp to
sp = dropTrailingPathSeparator . splitPath
sp = map dropTrailingPathSeparator . splitPath
common = map fst $ takeWhile same $ zip pfrom pto
same (c,d) = c = d
same (c,d) = c == d
uncommon = drop numcommon pto
dotdots = replicate (length pfrom - numcommon) ".."
numcommon = length common