From a6eb7d73398fc1729faec663c1822023e540643b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 5 Dec 2023 12:38:14 -0400 Subject: [PATCH] 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 --- CHANGELOG | 2 ++ Utility/Tmp.hs | 13 ++++++++++--- ..._argument_saving_FreeSurfer_file_on_NTFS.mdwn | 2 ++ ...t_1_181a319138cc10742bc8676d77e8a614._comment | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS/comment_1_181a319138cc10742bc8676d77e8a614._comment diff --git a/CHANGELOG b/CHANGELOG index bf4b7fe36d..ab8e557dca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ git-annex (10.20231130) UNRELEASED; urgency=medium remote.foo.annex-ignore, as documented. * Support git-annex copy/move --from-anywhere --to remote. * sync: Fix locking problems during merge when annex.pidlock is set. + * Avoid a problem with temp file names ending in "." on certian + filesystems that have problems with such filenames. -- Joey Hess Thu, 30 Nov 2023 14:48:12 -0400 diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs index efb15bd9b3..75048fcd8f 100644 --- a/Utility/Tmp.hs +++ b/Utility/Tmp.hs @@ -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 diff --git a/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS.mdwn b/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS.mdwn index 5b4e7db549..241ee8ce8c 100644 --- a/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS.mdwn +++ b/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS.mdwn @@ -91,3 +91,5 @@ add: 1 failed ### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders) Yes! I use git annex and datalad all the time for personal and work projects. + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS/comment_1_181a319138cc10742bc8676d77e8a614._comment b/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS/comment_1_181a319138cc10742bc8676d77e8a614._comment new file mode 100644 index 0000000000..0ab08545f2 --- /dev/null +++ b/doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS/comment_1_181a319138cc10742bc8676d77e8a614._comment @@ -0,0 +1,16 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2023-12-05T16:16:35Z" + content=""" +This is EINVAL from probably open(2) or something like that. + + EINVAL The final component ("basename") of pathname is invalid (e.g., + it contains characters not permitted by the underlying filesys‐ + tem). + +The problem is likely the ending ".", since FAT and probably other Microsoft filesystems +don't allow that, and/or have other strange behavior like silently removing that. + +Changed the code to avoid this. +"""]]