set fileEncoding in streamLogFileUnsafe
authorJoey Hess <joeyh@joeyh.name>
Thu, 8 May 2025 18:59:29 +0000 (14:59 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 8 May 2025 18:59:42 +0000 (14:59 -0400)
Windows: Fix bug that can cause git status to show annexed files as
modified when built with OsPath.

This may also have caused bugs on non-Windows, with filenames with
non-ascii characters? Unsure.

The OsPath conversion makes this one of the last few places
(hopefully) where a String is read from a Handle. All other fileEncoding
uses have been eliminated before this point by converting to reading
ByteString and using OsPath. Doing that here would be a better fix,
performance wise.

Sponsored-by: Jack Hill
CHANGELOG
Logs/File.hs
doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified.mdwn
doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified/comment_5_be63c011f1a7e327ce3c79125105644d._comment [new file with mode: 0644]

index f96e750319403601e57a59ba9b658d047ed7caa3..ef7fa0cf77a2deec5161dd3c37d4802668929229 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,8 @@ git-annex (10.20250417) UNRELEASED; urgency=medium
     repositories accessed via ssh.
   * whereused: Fix bug that could find matches from grafts 
     in remote git-annex branches.
+  * Windows: Fix bug that can cause git status to show annexed files as
+    modified when built with OsPath.
 
  -- Joey Hess <id@joeyh.name>  Tue, 22 Apr 2025 14:33:26 -0400
 
index ed9562788355200d9a4166296cdd604d4a29706f..882dc253691f443347e46834a0883930cdf4301a 100644 (file)
@@ -145,6 +145,7 @@ streamLogFileUnsafe f finalizer processor = bracketOnError setup cleanup go
        cleanup (Just h) = liftIO $ hClose h
        go Nothing = finalizer
        go (Just h) = do
+               liftIO $ fileEncoding h
                mapM_ processor =<< liftIO (lines <$> hGetContents h)
                liftIO $ hClose h
                finalizer
index 3a86583375a0638254b2faf0aeadd8685ad45d75..424553075ce84594569032ca3621891f7c5d38f3 100644 (file)
@@ -524,3 +524,5 @@ say I'm a believer. :)
 
 [[!meta author=jkniiv]]
 [[!meta title="(Windows) OsPath build of git-annex shows files needlessly modified in git status"]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified/comment_5_be63c011f1a7e327ce3c79125105644d._comment b/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified/comment_5_be63c011f1a7e327ce3c79125105644d._comment
new file mode 100644 (file)
index 0000000..1461bfb
--- /dev/null
@@ -0,0 +1,26 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 5"""
+ date="2025-05-08T18:03:11Z"
+ content="""
+In restagePointerFiles, isunmodified's call to genInodeCache is returning
+Nothing, and so it does not try to restage the file.
+
+The path to the annexed file includes "läp", and that non-ascii
+character is causing the problem. If I rename that to "lap", the problem
+goes away.
+
+Printing out the OsPath, I see `"l\195\164p"`. That seems wrong for
+Windows, where it should be using UTF-16. Calling `fromOsPath` on it to
+make a RawFilePath yields `"l\195\131\194\164p"` which is certainly wrong,
+and explains why genInodeCache, which does that conversion, is failing.
+
+So the question is how the OsPath is being constructed with the wrong
+encoding. In this case, it's coming from streamRestageLog.
+Which uses streamLogFileUnsafe. Which does not set the filesystem encoding
+when reading the log file. So that's the bug. I'm not sure if this bug is
+actually Windows specific, although the use of UTF16 on windows may be
+helping trigger a problem with it.
+
+Anyway, fixed it!
+"""]]