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

ghc::filesystem::remove_all fails if symlink target is pointing to a read only filesystem #132

Closed
CedricDC opened this issue Jul 14, 2021 · 4 comments
Assignees
Labels
available on master Fix is done on master branch, issue closed on next release bug Something isn't working POSIX POSIX type backend is affected
Milestone

Comments

@CedricDC
Copy link

Hi!

The call to ghc::filesystem::remove_all(path) (same with the version with the std::error_code) appears to fail when "path" is a symlink on a read-write filesystem that points to a non-empty directory on a read-only filesystem. It works correctly when the symlink target is a file or if the target directory is empty. The call returns an error with the "Read-only file system" message.

Tested on Ubuntu 18.04 with gcc 9.2.0 with filesystem 1.0.8 as well as current master. Using std::filesystem instead, the symlink is deleted as expected.

Test procedure:

  1. Create virtual filesystem as described here : https://www.thegeekdiary.com/how-to-create-virtual-block-device-loop-device-filesystem-in-linux/ (or use real one, whatever is available)
  2. Create directory test_dir with a file in it
  3. Remount filesystem as read-only.
  4. Create symlink (called sym_test_dir in the example below) to test_dir from a different, read-write filesystem and try to delete that symlink via remove_all

Sample executable:

#include <iostream>
#include <string>

#include "ghc_filesystem.hpp"

namespace fs = ghc::filesystem;

void removeSomething(const std::string& name) {
  std::error_code ec_remove;
  fs::remove_all(name, ec_remove);
  if (ec_remove.value() != 0) {
    std::string msg = ec_remove.message();
    std::cout << "Could not remove " << name << ": " << msg << std::endl;
  } else {
    std::cout << "Happily removed " << name << std::endl;
  }
}

int main() {

  std::string symlink_path = "sym_test_dir";

  // try to remove non-empty dir --> fails with "Read-only file system"
  removeSomething(symlink_dir);

  return 0;
}

Thanks!

@gulrak gulrak self-assigned this Jul 14, 2021
@gulrak gulrak added bug Something isn't working POSIX POSIX type backend is affected labels Jul 14, 2021
@gulrak
Copy link
Owner

gulrak commented Jul 14, 2021

Thank you for the detailed report, I'll look into it.

@phprus
Copy link
Contributor

phprus commented Sep 16, 2021

@CedricDC
Please replace line

auto fs = status(p, tec);

to

auto fs = symlink_status(p, tec);

and run your test.

gulrak added a commit that referenced this issue Oct 1, 2021
@gulrak gulrak added this to the v1.5.10 milestone Oct 1, 2021
@gulrak
Copy link
Owner

gulrak commented Oct 1, 2021

This is indeed be fixed by #135 and I want to thank @phprus for his repeated supportive work.

@gulrak gulrak added the available on master Fix is done on master branch, issue closed on next release label Oct 1, 2021
@gulrak
Copy link
Owner

gulrak commented Oct 23, 2021

Fix is part of v1.5.10.

@gulrak gulrak closed this as completed Oct 23, 2021
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 POSIX POSIX type backend is affected
Projects
None yet
Development

No branches or pull requests

3 participants