Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use readFile #5741

Closed
nad opened this issue Jan 15, 2022 · 3 comments
Closed

Do not use readFile #5741

nad opened this issue Jan 15, 2022 · 3 comments
Assignees
Labels
type: bug Issues and pull requests about actual bugs unicode
Milestone

Comments

@nad
Copy link
Contributor

nad commented Jan 15, 2022

I noticed that the code uses readFile to read certain files that are (or should be) required to use the UTF-8 text encoding:

readDefaultsFile :: LibErrorIO [LibName]
readDefaultsFile = do
agdaDir <- liftIO getAgdaAppDir
let file = agdaDir </> defaultsFile
ifNotM (liftIO $ doesFileExist file) (return []) $ {-else-} do
ls <- liftIO $ map snd . stripCommentLines <$> readFile file

getInstalledLibraries
:: Maybe FilePath -- ^ Override the default @libraries@ file?
-> LibM [AgdaLibFile] -- ^ Content of library files. (Might have empty @LibName@s.)
getInstalledLibraries overrideLibFile = mkLibM [] $ do
filem <- liftIO $ runExceptT $ getLibrariesFile overrideLibFile
case filem of
Left err -> raiseErrors' [OtherError err] >> return []
Right file -> do
if not (lfExists file) then return [] else do
ls <- liftIO $ stripCommentLines <$> readFile (lfPath file)

getTrustedExecutables
:: LibM (Map ExeName FilePath) -- ^ Content of @executables@ files.
getTrustedExecutables = mkLibM [] $ do
file <- liftIO getExecutablesFile
if not (efExists file) then return Map.empty else do
es <- liftIO $ stripCommentLines <$> readFile (efPath file)

parseLibFile :: FilePath -> IO (P AgdaLibFile)
parseLibFile file =
(fmap setPath . parseLib <$> readFile file) `catchIO` \e ->

These calls to readFile should all be fixed.

@nad nad added type: bug Issues and pull requests about actual bugs unicode labels Jan 15, 2022
@nad nad added this to the 2.6.3 milestone Jan 15, 2022
@andreasabel
Copy link
Member

andreasabel commented Jan 15, 2022

These calls to readFile should all be fixed.

How? What do you suggest?
Use readTextFile from #5742?

@nad
Copy link
Contributor Author

nad commented Jan 15, 2022

I guess you meant some other issue, but I think it is appropriate to use Agda.Utils.IO.UTF8.readTextFile to read these files.

@nad nad self-assigned this Jan 15, 2022
nad added a commit that referenced this issue Jan 15, 2022
@andreasabel
Copy link
Member

I guess you meant some other issue.

I think I meant #5740.

@nad nad closed this as completed in 63de398 Jan 16, 2022
@andreasabel andreasabel modified the milestones: 2.6.3, 2.6.2.2 Mar 14, 2022
andreasabel pushed a commit that referenced this issue Mar 15, 2022
@andreasabel andreasabel mentioned this issue Mar 15, 2022
41 tasks
andreasabel pushed a commit that referenced this issue Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Issues and pull requests about actual bugs unicode
Projects
None yet
Development

No branches or pull requests

2 participants