]> dgit.raspbian.org Git - git-annex.git/commitdiff
break out templateAddedLength
authorJoey Hess <joeyh@joeyh.name>
Wed, 22 Jan 2025 15:43:45 +0000 (11:43 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 22 Jan 2025 15:43:45 +0000 (11:43 -0400)
Utility/Tmp.hs

index 21b6fed9de488871cc3e2f91f7f187428ce1a8c4..8594f908ae477271d541f7a615c31f6008a3fb39 100644 (file)
@@ -104,19 +104,26 @@ withTmpFileIn tmpdir template a = bracket create remove use
  - will be longer, and may exceed the maximum filename length.
  -
  - This generates a template that is never too long.
- - (Well, it allocates 20 characters for use in making a unique temp file,
- - anyway, which is enough for the current implementation and any
- - likely implementation.)
  -}
 relatedTemplate :: RawFilePath -> Template
 relatedTemplate f
-       | len > 20 = 
+       | len > templateAddedLength = 
                {- Some filesystems like FAT have issues with filenames
                 - ending in ".", so avoid truncating a filename to end
                 - that way. -}
                toOsPath $ toRawFilePath $ 
                        reverse $ dropWhile (== '.') $ reverse $
-                               truncateFilePath (len - 20) (fromRawFilePath f)
+                               truncateFilePath (len - templateAddedLength) (fromRawFilePath f)
        | otherwise = toOsPath f
   where
        len = B.length f
+
+{- When a Template is used to create a temporary file, some random bytes
+ - are appended to it. This is how many such bytes can be added, maximum.
+ -
+ - This needs to be as long or longer than the current implementation
+ - of openTempFile, and some extra has been added to make it longer
+ - than any likely implementation.
+ -}
+templateAddedLength :: Int
+templateAddedLength = 20