prevent relatedTemplate from truncating a filename to end in whitespace
authorJoey Hess <joeyh@joeyh.name>
Mon, 23 Jun 2025 17:31:15 +0000 (13:31 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 23 Jun 2025 17:31:15 +0000 (13:31 -0400)
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
Utility/Tmp.hs
doc/bugs/openTempfile_invalid_argument_on_sd_card.mdwn

index 2b2823d998f90c14b0c4374823ca632b4b57fcb6..2ce4f60831e9f093e168c66ad883733b9953be9c 100644 (file)
--- 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 <id@joeyh.name>  Mon, 23 Jun 2025 11:11:29 -0400
 
index f8be5b29c01d794bf830db63ed59fe9383665096..f373ca6c1c8cefc2ab31fbb7f4917ddcfbcd3e63 100644 (file)
@@ -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
index f3c37c53270a71a6c8ae2f2ec19637bd4c738cc5..2763ae3a1710d2ef4c01a5176b6fa29237f93bef 100644 (file)
@@ -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]]