From de7dae06cf551bc49a34e5afb9434792481e44b3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 May 2025 14:59:29 -0400 Subject: [PATCH] set fileEncoding in streamLogFileUnsafe 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 | 2 ++ Logs/File.hs | 1 + ...f_g-a_shows_files_needlessly_modified.mdwn | 2 ++ ..._be63c011f1a7e327ce3c79125105644d._comment | 26 +++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified/comment_5_be63c011f1a7e327ce3c79125105644d._comment diff --git a/CHANGELOG b/CHANGELOG index f96e750319..ef7fa0cf77 100644 --- 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 Tue, 22 Apr 2025 14:33:26 -0400 diff --git a/Logs/File.hs b/Logs/File.hs index ed95627883..882dc25369 100644 --- a/Logs/File.hs +++ b/Logs/File.hs @@ -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 diff --git a/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified.mdwn b/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified.mdwn index 3a86583375..424553075c 100644 --- a/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified.mdwn +++ b/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified.mdwn @@ -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 index 0000000000..1461bfb3d5 --- /dev/null +++ b/doc/bugs/OsPath_bld_of_g-a_shows_files_needlessly_modified/comment_5_be63c011f1a7e327ce3c79125105644d._comment @@ -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! +"""]] -- 2.30.2