add: When adding a dotfile, avoid treating its name as an extension.

This commit is contained in:
Joey Hess 2021-08-03 12:22:58 -04:00
parent 2572950ca7
commit 899983058f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 12 additions and 1 deletions

View file

@ -59,8 +59,11 @@ selectExtension maxlen f
es = filter (not . S.null) $ reverse $
take 2 $ filter (S.all validInExtension) $
takeWhile shortenough $
reverse $ S.split (fromIntegral (ord '.')) (P.takeExtensions f)
reverse $ S.split (fromIntegral (ord '.')) (P.takeExtensions f')
shortenough e = S.length e <= fromMaybe maxExtensionLen maxlen
-- Avoid treating a file ".foo" as having its whole name as an
-- extension.
f' = S.dropWhile (== fromIntegral (ord '.')) (P.takeFileName f)
validInExtension :: Word8 -> Bool
validInExtension c