From 2007507e2bf1cdc81ca678972c44a017f198cee9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 23 Jun 2025 13:31:15 -0400 Subject: [PATCH] prevent relatedTemplate from truncating a filename to end in whitespace Avoid a problem with temp file names ending in whitespace on filesystems like VFAT that don't support such filenames. See a6eb7d73398fc1729faec663c1822023e540643b previously for the same but with "." At some point relatedTemplate is more bother than it's worth and it would be simpler to just use "temp" as the basename of all temp files. We seem to be approaching that point, since my interest in absurd ancient filesystem limitations is limited. Sponsored-by: unqueued on Patreon --- CHANGELOG | 2 ++ Utility/Tmp.hs | 8 +++++--- doc/bugs/openTempfile_invalid_argument_on_sd_card.mdwn | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2b2823d998..2ce4f60831 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ git-annex (10.20250606) UNRELEASED; urgency=medium * Skip and warn when a tree import includes empty filenames, which can happen with eg a S3 bucket. + * Avoid a problem with temp file names ending in whitespace on + filesystems like VFAT that don't support such filenames. -- Joey Hess Mon, 23 Jun 2025 11:11:29 -0400 diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs index f8be5b29c0..f373ca6c1c 100644 --- a/Utility/Tmp.hs +++ b/Utility/Tmp.hs @@ -117,13 +117,15 @@ relatedTemplate' :: RawFilePath -> RawFilePath relatedTemplate' f | len > templateAddedLength = {- Some filesystems like FAT have issues with filenames - - ending in ".", so avoid truncating a filename to end - - that way. -} - B.dropWhileEnd (== dot) $ + - ending in ".", and others like VFAT don't allow a + - filename to end with trailing whitespace, so avoid + - truncating a filename to end that way. -} + B.dropWhileEnd disallowed $ truncateFilePath (len - templateAddedLength) f | otherwise = f where len = B.length f + disallowed c = c == dot || isSpace (chr (fromIntegral c)) dot = fromIntegral (ord '.') #else -- Avoids a test suite failure on windows, reason unknown, but diff --git a/doc/bugs/openTempfile_invalid_argument_on_sd_card.mdwn b/doc/bugs/openTempfile_invalid_argument_on_sd_card.mdwn index f3c37c5327..2763ae3a17 100644 --- a/doc/bugs/openTempfile_invalid_argument_on_sd_card.mdwn +++ b/doc/bugs/openTempfile_invalid_argument_on_sd_card.mdwn @@ -43,3 +43,5 @@ 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) I use it quite successfully to archive media on removable spinning hard drives. + +> [[fixed|done]] --[[Joey]]