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

Symlink treated as directory #5

Closed
Tracked by #9
andreasabel opened this issue Jul 29, 2022 · 7 comments · Fixed by #6
Closed
Tracked by #9

Symlink treated as directory #5

andreasabel opened this issue Jul 29, 2022 · 7 comments · Fixed by #6

Comments

@andreasabel
Copy link
Contributor

This is

Reproducer in filepattern-0.1.2:

$ mkdir dir
$ mkdir dir/a
$ mkdir dir/b
$ touch dir/a/file
$ ln -s dir/a/file dir/b/file
$ tree
.
└── dir
    ├── a
    │   └── file
    └── b
        └── file -> dir/a/file
$ ghci
GHCi, version 9.2.3: https://www.haskell.org/ghc/  :? for help
ghci> :m + System.FilePattern.Directory
ghci> getDirectoryFiles "." ["**"]
*** Exception: ./dir/b/file/: getDirectoryContents:openDirStream: does not exist (No such file or directory)
@andreasabel
Copy link
Contributor Author

Relevant code:

isFile <- whenMaybe (stepDone yes /= [] && stepDone no == []) (doesFileExist path)
case isFile of
Just True -> pure [parts ++ x]
_ | StepEverything <- stepNext no -> pure []
| StepOnly [] <- stepNext yes -> pure []
| otherwise -> do
b <- if doesExist && isFile == Just False then pure True else doesDirectoryExist path
if not b then pure [] else f (parts ++ x ++ "/") yes no

In
b <- if doesExist && isFile == Just False then pure True else doesDirectoryExist path

we get isFile == Just False for a symlink, which is then treated as directory.
The docs for doesFileExist are misleading (outright wrong):
https://hackage.haskell.org/package/directory-1.3.7.1/docs/System-Directory.html#v:doesFileExist

The operation doesFileExist returns True if the argument file exists and is not a directory, and False otherwise.

@andreasabel
Copy link
Contributor Author

andreasabel commented Jul 29, 2022

Since if doesExist && isFile == Just False then pure True isn't working for symlinks, we need to check doesDirectoryExist anyway, thus can get rid of the doesExist optimization altogether. Implemented in:

@andreasabel
Copy link
Contributor Author

Ping @ndmitchell.

@ndmitchell
Copy link
Owner

Thanks for the diff @andreasabel - unfortunately you've caught me as I'm travelling and otherwise unavailable. Hopefully will take a proper look at this tomorrow.

ndmitchell added a commit that referenced this issue Aug 21, 2022
Fix #5 by removing doesExist optimisation in getDirectoryFiles
@andreasabel
Copy link
Contributor Author

Thanks for merging! Please ping me when you release, so I can depend on the latest version.

@ndmitchell
Copy link
Owner

@andreasabel 0.1.3 now released with this fix

@andreasabel
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants