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

fs::file_info hangs for symlinks of symlinks #440

Open
DE0CH opened this issue Jan 7, 2024 · 3 comments
Open

fs::file_info hangs for symlinks of symlinks #440

DE0CH opened this issue Jan 7, 2024 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@DE0CH
Copy link

DE0CH commented Jan 7, 2024

It seems like fs::is_file('/opt/homebrew/bin/python3') hangs on Mac with homebrew python installed. This doesn't seem to be a Mac specific bug because I was able to reproduce it by recreating the folder structure and symlinks on a linux computer I have.

Steps to reproduce

Create symlinks and folder structure with the script below

mkdir -p opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/bin
cd opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/bin
echo "#!/bin/sh
echo 'hi'
" > python3.11
chmod +x python3.11
ln -s python3.11 python3
cd ../../../../../../../../../../
mkdir -p opt/homebrew/Cellar/python@3.11/3.11.6_1/bin
cd opt/homebrew/Cellar/python@3.11/3.11.6_1/bin
ln -s ../Frameworks/Python.framework/Versions/3.11/bin/python3 python3
cd ../../../../../../
mkdir -p opt/homebrew/bin
cd opt/homebrew/bin
ln -s ../Cellar/python@3.11/3.11.6_1/bin/python3 python3
cd ../../../

And then run fs::is_file('opt/homebrew/bin/python3') to see it hangs.

Version Information

$ R --version
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

I installed the version of fs from GitHub, which is at 8a84fc9 at the time of writing.

@MLopez-Ibanez
Copy link

A pure R reproducer:

library(fs)
file_touch("file")
link_create("file", "link1")
link_create("link1", "link2")
is_file("link2")

It seems the loop that follows symlinks is broken:

fs/R/file.R

Lines 64 to 69 in 8a84fc9

while(follow && any(is_symlink)) {
lpath <- link_path(path[is_symlink])
lpath <- ifelse(is_absolute_path(lpath), lpath, path(path_dir(path[is_symlink]), lpath))
res[is_symlink, ] <- file_info(lpath, fail = fail, follow = FALSE)
is_symlink <- !is.na(res$type) & res$type == "symlink"
}

path is never updated within the loop, so lpath has the same value in the second iteration.

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Jan 7, 2024
@MLopez-Ibanez
Copy link

This is not only on Mac, I am using Ubuntu 20.04.

@MLopez-Ibanez
Copy link

And the bug is actually in file_info(), so any function using that is affected.

@DE0CH DE0CH changed the title fs::is_file hangs for homebrew python on Mac fs::file_info hangs for symlinks of symlinks Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants