This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2681. filesystem::copy() cannot copy symlinks

Section: 31.12.13.4 [fs.op.copy] Status: C++17 Submitter: Jonathan Wakely Opened: 2016-04-19 Last modified: 2017-07-30

Priority: 2

View all other issues in [fs.op.copy].

View all issues with C++17 status.

Discussion:

31.12.13.4 [fs.op.copy] paragraph 3 bullet (3.4) says that if is_symlink(f) and copy_options is set in options then it should copy a symlink, but that case cannot be reached.

is_symlink(f) can only be true if f was set using symlink_status(from), but that doesn't happen unless one of create_symlinks or skip_symlinks is set in options. It should depend on copy_symlinks too.

I'm not sure what the correct behaviour is, but I don't think we want to simply add a check for copy_symlinks in bullet (3.1) because that would mean that t = symlink_status(to), and I don't think we want that. Consider 'touch file; mkdir dir; ln -s dir link;' and then filesystem::copy("file", "link", filesystem::copy_options::copy_symlinks). If t = symlink_status(to) then is_directory(t) == false, and we don't use bullet (3.5.4) but go to (3.5.5) instead and fail. So when copy_symlinks is set we still need to use t = status(to) as specified today.

[2016-05 Issues Telecon]

This is related to 2682; and should be considered together.

[2016-08 Chicago]

Wed AM: Move to Tentatively Ready

Proposed resolution:

Modify paragraph 3 of 31.12.13.4 [fs.op.copy] as shown:

Effects: Before the first use of f and t:

— If (options & copy_options::create_symlinks) != copy_options::none || (options & copy_options::skip_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = symlink_status(to).

— Otherwise, if (options & copy_options::copy_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = status(to).
— Otherwise, auto f = status(from) and if needed auto t = status(to).