more OsPath conversion

Sponsored-by: Kevin Mueller
This commit is contained in:
Joey Hess 2025-01-29 16:24:51 -04:00
parent c309edb8fb
commit a9f3a31a52
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 41 additions and 39 deletions

View file

@ -42,12 +42,11 @@ import qualified Utility.FileIO as F
import qualified Data.ByteString.Lazy.Char8 as L8
import qualified Data.ByteString.Char8 as S8
import qualified Data.Map as M
import qualified System.FilePath.ByteString as P
{- A CredPair can be stored in a file, or in the environment, or
- in a remote's configuration. -}
data CredPairStorage = CredPairStorage
{ credPairFile :: FilePath
{ credPairFile :: OsPath
, credPairEnvironment :: (String, String)
, credPairRemoteField :: RemoteConfigField
}
@ -196,21 +195,21 @@ existsCacheCredPair storage =
{- Stores the creds in a file inside gitAnnexCredsDir that only the user
- can read. -}
writeCreds :: Creds -> FilePath -> Annex ()
writeCreds :: Creds -> OsPath -> Annex ()
writeCreds creds file = do
d <- fromRepo gitAnnexCredsDir
createAnnexDirectory d
liftIO $ writeFileProtected (d P.</> toRawFilePath file) creds
liftIO $ writeFileProtected (d </> file) creds
readCreds :: FilePath -> Annex (Maybe Creds)
readCreds :: OsPath -> Annex (Maybe Creds)
readCreds f = do
f' <- toOsPath . toRawFilePath <$> credsFile f
f' <- credsFile f
liftIO $ catchMaybeIO $ decodeBS . S8.unlines . fileLines'
<$> F.readFile' f'
credsFile :: FilePath -> Annex FilePath
credsFile :: OsPath -> Annex OsPath
credsFile basefile = do
d <- fromRawFilePath <$> fromRepo gitAnnexCredsDir
d <- fromRepo gitAnnexCredsDir
return $ d </> basefile
encodeCredPair :: CredPair -> Creds
@ -221,10 +220,10 @@ decodeCredPair creds = case lines creds of
l:p:[] -> Just (l, p)
_ -> Nothing
removeCreds :: FilePath -> Annex ()
removeCreds :: OsPath -> Annex ()
removeCreds file = do
d <- fromRepo gitAnnexCredsDir
liftIO $ removeWhenExistsWith R.removeLink (d P.</> toRawFilePath file)
liftIO $ removeWhenExistsWith R.removeLink (fromOsPath (d </> file))
includeCredsInfo :: ParsedRemoteConfig -> CredPairStorage -> [(String, String)] -> Annex [(String, String)]
includeCredsInfo pc@(ParsedRemoteConfig cm _) storage info = do