prevent relatedTemplate from truncating a filename to end in "."
Avoid a problem with temp file names ending in "." on certian filesystems that have problems with such filenames. relatedTemplate is quite an ugly hack really; since it doesn't know the max filename length of the filesystem it can only assume that the filename is max allowed length. When given the input "lh.aparc.DKTatlas.annot", it wants to reserve 20 characters for tempfile so it truncates to "lh.". That ending period is apparently a problem on some filesystem (FAT eats it, but does not throw EINVAL; ntfs does not seem bothered by it, I don't know what FUSE filesystem the bug reporter was really using). Sponsored-by: Brett Eisenberg on Patreon
This commit is contained in:
parent
9aa53212a9
commit
a6eb7d7339
4 changed files with 30 additions and 3 deletions
|
@ -35,8 +35,10 @@ type Template = String
|
|||
- to help identify what call was responsible.
|
||||
-}
|
||||
openTmpFileIn :: FilePath -> String -> IO (FilePath, Handle)
|
||||
openTmpFileIn dir template = openTempFile dir template
|
||||
`catchIO` decoraterrror
|
||||
openTmpFileIn dir template = do
|
||||
liftIO $ print ("openTmpFileIn", dir, template)
|
||||
openTempFile dir template
|
||||
`catchIO` decoraterrror
|
||||
where
|
||||
decoraterrror e = throwM $
|
||||
let loc = ioeGetLocation e ++ " template " ++ template
|
||||
|
@ -105,7 +107,12 @@ withTmpFileIn tmpdir template a = bracket create remove use
|
|||
-}
|
||||
relatedTemplate :: FilePath -> FilePath
|
||||
relatedTemplate f
|
||||
| len > 20 = truncateFilePath (len - 20) f
|
||||
| len > 20 =
|
||||
{- Some filesystems like FAT have issues with filenames
|
||||
- ending in ".", so avoid truncating a filename to end
|
||||
- that way. -}
|
||||
reverse $ dropWhile (== '.') $ reverse $
|
||||
truncateFilePath (len - 20) f
|
||||
| otherwise = f
|
||||
where
|
||||
len = length f
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue