prevent relatedTemplate from truncating a filename to end in "."
authorJoey Hess <joeyh@joeyh.name>
Tue, 5 Dec 2023 16:38:14 +0000 (12:38 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 5 Dec 2023 16:38:14 +0000 (12:38 -0400)
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
Utility/Tmp.hs
doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS.mdwn
doc/bugs/Invalid_argument_saving_FreeSurfer_file_on_NTFS/comment_1_181a319138cc10742bc8676d77e8a614._comment [new file with mode: 0644]

index bf4b7fe36d0b61be6a29cbc46f909a28788025e8..ab8e557dca630fbe4887c02e19188314e659d82a 100644 (file)
--- 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 <id@joeyh.name>  Thu, 30 Nov 2023 14:48:12 -0400
 
index efb15bd9b363f03f6222f0af1a21348eb3c1c3b8..75048fcd8fede478b81a3c58fca224bae0aa73de 100644 (file)
@@ -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
index 5b4e7db5499aa1100be64811615faa663d911df1..241ee8ce8c7061c3e78626188e22486cc6a92727 100644 (file)
@@ -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 (file)
index 0000000..0ab0854
--- /dev/null
@@ -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.
+"""]]