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

directory_entry::refresh() throws on broken symlinks #151

Closed
ilyapopov opened this issue Jun 26, 2022 · 3 comments
Closed

directory_entry::refresh() throws on broken symlinks #151

ilyapopov opened this issue Jun 26, 2022 · 3 comments
Assignees
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working
Milestone

Comments

@ilyapopov
Copy link

ilyapopov commented Jun 26, 2022

Describe the bug
In presence of a broken symlink, directory_entry::refresh() throws, while both status() and symlink_status() succeed.
Under the same circumstances, libstdc++ succeeds.

To Reproduce

#ifndef USE_GHC_FILESYSTEM
#    include <filesystem>
namespace fs = std::filesystem;
#else
#    include "ghc/filesystem.hpp"
namespace fs = ghc::filesystem;
#endif

#include <iostream>

int main() {
    // create a broken symlink
    if (fs::is_symlink("broken")) {
        fs::remove("broken");
    }
    fs::create_symlink("nonexistent", "broken");

    for (auto entry: fs::directory_iterator(".")) {
        std::cout << entry.path() << '\n';
        // this works
        entry.symlink_status();
        //this works
        entry.status();
        //this throws
        entry.refresh();
    }

    // non-iterating version behaves the same:
    fs::directory_entry entry("broken");
    entry.refresh();
}
$ g++ test1.cpp -DUSE_GHC_FILESYSTEM -I path/to/ghc_filesystem/include/ -o ghc
$ g++ test1.cpp -o gcc
./gcc
./ghc

Clang with libc++ behaves the same as GCC.

Expected behavior

I expect refresh() succeed and save file_status(file_type::not_found) into directory_entry instead.

Additional context

OS: Ubuntu 22.04
gcc: gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1)
ghc_filesystem: cd6805e
clang++: Ubuntu clang version 14.0.0-1ubuntu1

https://en.cppreference.com/w/cpp/filesystem/status
https://en.cppreference.com/w/cpp/filesystem/directory_entry/refresh

@gulrak gulrak added this to the v1.5.14 milestone Mar 3, 2023
@gulrak gulrak self-assigned this Mar 3, 2023
@gulrak gulrak added the bug Something isn't working label Mar 3, 2023
@gulrak
Copy link
Owner

gulrak commented Mar 4, 2023

I decided to fix the exception for broken symlinks as that is driven by external factors, but keep the behavior for initializing a directory_entry with an empty or non existing file as that is more often a usage error I keep wanting to assert. The specs are not clear to me there, and I try to not change behavior not explicitly defined as it is surprising for users of ghc::fs, but I think this change is for the better and more consistent.

@gulrak gulrak added the available on master Fix is done on master branch, issue closed on next release label Mar 4, 2023
@gulrak
Copy link
Owner

gulrak commented Mar 5, 2023

Released with v1.5.14.

@gulrak gulrak closed this as completed Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants