windows build fix

and a little more bonus RawFilePath conversion
This commit is contained in:
Joey Hess 2025-01-28 15:59:45 -04:00
parent da9ca7475e
commit 2b12f9f4b7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 13 additions and 13 deletions

View file

@ -241,7 +241,7 @@ checkDiskSpaceDirectory d k = do
- down. -} - down. -}
finalizeStoreGeneric :: RawFilePath -> RawFilePath -> RawFilePath -> IO () finalizeStoreGeneric :: RawFilePath -> RawFilePath -> RawFilePath -> IO ()
finalizeStoreGeneric d tmp dest = do finalizeStoreGeneric d tmp dest = do
removeDirGeneric False (fromRawFilePath d) dest' removeDirGeneric False d dest
createDirectoryUnder [d] (parentDir dest) createDirectoryUnder [d] (parentDir dest)
renameDirectory (fromRawFilePath tmp) dest' renameDirectory (fromRawFilePath tmp) dest'
-- may fail on some filesystems -- may fail on some filesystems
@ -275,9 +275,7 @@ retrieveKeyFileCheapM _ _ = Nothing
#endif #endif
removeKeyM :: RawFilePath -> Remover removeKeyM :: RawFilePath -> Remover
removeKeyM d _proof k = liftIO $ removeDirGeneric True removeKeyM d _proof k = liftIO $ removeDirGeneric True d (storeDir d k)
(fromRawFilePath d)
(fromRawFilePath (storeDir d k))
{- Removes the directory, which must be located under the topdir. {- Removes the directory, which must be located under the topdir.
- -
@ -293,28 +291,30 @@ removeKeyM d _proof k = liftIO $ removeDirGeneric True
- can also be removed. Failure to remove such a directory is not treated - can also be removed. Failure to remove such a directory is not treated
- as an error. - as an error.
-} -}
removeDirGeneric :: Bool -> FilePath -> FilePath -> IO () removeDirGeneric :: Bool -> RawFilePath -> RawFilePath -> IO ()
removeDirGeneric removeemptyparents topdir dir = do removeDirGeneric removeemptyparents topdir dir = do
void $ tryIO $ allowWrite (toRawFilePath dir) void $ tryIO $ allowWrite dir
#ifdef mingw32_HOST_OS #ifdef mingw32_HOST_OS
{- Windows needs the files inside the directory to be writable {- Windows needs the files inside the directory to be writable
- before it can delete them. -} - before it can delete them. -}
void $ tryIO $ mapM_ (allowWrite . toRawFilePath) =<< dirContents dir void $ tryIO $ mapM_ allowWrite =<< dirContents dir
#endif #endif
tryNonAsync (removeDirectoryRecursive dir) >>= \case tryNonAsync (removeDirectoryRecursive dir') >>= \case
Right () -> return () Right () -> return ()
Left e -> Left e ->
unlessM (doesDirectoryExist topdir <&&> (not <$> doesDirectoryExist dir)) $ unlessM (doesDirectoryExist topdir' <&&> (not <$> doesDirectoryExist dir')) $
throwM e throwM e
when removeemptyparents $ do when removeemptyparents $ do
subdir <- relPathDirToFile (toRawFilePath topdir) (P.takeDirectory (toRawFilePath dir)) subdir <- relPathDirToFile topdir (P.takeDirectory dir)
goparents (Just (P.takeDirectory subdir)) (Right ()) goparents (Just (P.takeDirectory subdir)) (Right ())
where where
goparents _ (Left _e) = return () goparents _ (Left _e) = return ()
goparents Nothing _ = return () goparents Nothing _ = return ()
goparents (Just subdir) _ = do goparents (Just subdir) _ = do
let d = topdir </> fromRawFilePath subdir let d = topdir' </> fromRawFilePath subdir
goparents (upFrom subdir) =<< tryIO (removeDirectory d) goparents (upFrom subdir) =<< tryIO (removeDirectory d)
dir' = fromRawFilePath dir
topdir' = fromRawFilePath topdir
checkPresentM :: RawFilePath -> ChunkConfig -> CheckPresent checkPresentM :: RawFilePath -> ChunkConfig -> CheckPresent
checkPresentM d (LegacyChunks _) k = Legacy.checkKey d locations' k checkPresentM d (LegacyChunks _) k = Legacy.checkKey d locations' k

View file

@ -439,8 +439,8 @@ remove' :: Git.Repo -> Remote -> Remote.Rsync.RsyncOpts -> AccessMethod -> Remov
remove' repo r rsyncopts accessmethod proof k remove' repo r rsyncopts accessmethod proof k
| not $ Git.repoIsUrl repo = guardUsable repo (giveup "cannot access remote") $ | not $ Git.repoIsUrl repo = guardUsable repo (giveup "cannot access remote") $
liftIO $ Remote.Directory.removeDirGeneric True liftIO $ Remote.Directory.removeDirGeneric True
(gCryptTopDir repo) (toRawFilePath (gCryptTopDir repo))
(fromRawFilePath (parentDir (toRawFilePath (gCryptLocation repo k)))) (parentDir (toRawFilePath (gCryptLocation repo k)))
| Git.repoIsSsh repo = shellOrRsync r removeshell removersync | Git.repoIsSsh repo = shellOrRsync r removeshell removersync
| accessmethod == AccessRsyncOverSsh = removersync | accessmethod == AccessRsyncOverSsh = removersync
| otherwise = unsupportedUrl | otherwise = unsupportedUrl