Skip to content

Commit

Permalink
Fix agda#7331: handle permission error when search for project file
Browse files Browse the repository at this point in the history
Closes agda#7331.
  • Loading branch information
andreasabel committed Jun 26, 2024
1 parent 2ec1cad commit 777b07f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/full/Agda/Interaction/Library.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import qualified Data.Text as T
import System.Directory
import System.FilePath
import System.Environment
import System.IO.Error ( isPermissionError )

import Agda.Interaction.Library.Base
import Agda.Interaction.Library.Parse
Expand Down Expand Up @@ -191,7 +192,7 @@ findProjectConfig'
findProjectConfig' root = do
getCachedProjectConfig root >>= \case
Just conf -> return conf
Nothing -> do
Nothing -> handlePermissionException do
libFiles <- liftIO $ getDirectoryContents root >>=
filterM (\file -> and2M
(pure $ takeExtension file == ".agda-lib")
Expand All @@ -215,6 +216,13 @@ findProjectConfig' root = do
return conf

where
-- Andreas, 2024-06-26, issue #7331:
-- In case of missing permission we terminate our search for the project file
-- with the default value.
handlePermissionException :: LibErrorIO ProjectConfig -> LibErrorIO ProjectConfig
handlePermissionException = flip catchIO \ e ->
if isPermissionError e then return DefaultProjectConfig else liftIO $ E.throwIO e

-- Note that "going up" one directory is OS dependent
-- if the directory is a symlink.
--
Expand Down
Empty file added test/interaction/Issue7331.agda
Empty file.
1 change: 1 addition & 0 deletions test/interaction/Issue7331.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checking Issue7331 (Issue7331/dir/Issue7331.agda).
23 changes: 23 additions & 0 deletions test/interaction/Issue7331.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Andreas, 2024-06-26, issue #7331:
# Handle permission error sensibly when looking for project root.

AGDA=${1}

mkdir -p Issue7331/dir > /dev/null
touch Issue7331/dir/Issue7331.agda > /dev/null
pushd Issue7331/dir > /dev/null

# Drop permissions for parent dir
chmod -r .. > /dev/null

${AGDA} --ignore-interfaces Issue7331.agda
result=$?

# Clean up
popd > /dev/null
chmod +r Issue7331 > /dev/null
rm -rf Issue7331 > /dev/null

exit $result

0 comments on commit 777b07f

Please sign in to comment.