<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2681: filesystem::copy() cannot copy symlinks</title>
<meta property="og:title" content="Issue 2681: filesystem::copy() cannot copy symlinks">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2681.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2681"><a href="lwg-defects.html#2681">2681</a>. <code>filesystem::copy()</code> cannot copy symlinks</h3>
<p><b>Section:</b> 31.12.13.4 <a href="https://wg21.link/fs.op.copy">[fs.op.copy]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2016-04-19 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#fs.op.copy">issues</a> in [fs.op.copy].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>31.12.13.4 <a href="https://wg21.link/fs.op.copy">[fs.op.copy]</a> paragraph 3 bullet (3.4) says that if <code>is_symlink(f)</code> and
<code>copy_options</code> is set in options then it should copy a symlink, but that
case cannot be reached.</p>

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

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

<p><i>[2016-05 Issues Telecon]</i></p>

<p>
This is related to <a href="lwg-defects.html#2682" title="filesystem::copy() won't create a symlink to a directory (Status: C++20)">2682</a><sup><a href="https://cplusplus.github.io/LWG/issue2682" title="Latest snapshot">(i)</a></sup>; and should be considered together.
</p>

<p><i>[2016-08 Chicago]</i></p>

<p>Wed AM: Move to Tentatively Ready</p>


<p id="res-2681"><b>Proposed resolution:</b></p>
<p>Modify paragraph 3 of 31.12.13.4 <a href="https://wg21.link/fs.op.copy">[fs.op.copy]</a> as shown:</p>

<blockquote>
<p><i>Effects:</i> Before the first use of <code>f</code> and <code>t</code>:<br/><br/>
 — If <code>(options &amp; copy_options::create_symlinks) != copy_options::none ||
(options &amp; copy_options::skip_symlinks) != copy_options::none</code>
then <code>auto f = symlink_status(from)</code> and if needed <code>auto t = symlink_status(to)</code>.<br/><br/>
<ins>
 — Otherwise, if <code>(options &amp; copy_options::copy_symlinks) != copy_options::none</code>
then <code>auto f = symlink_status(from)</code> and if needed <code>auto t = status(to)</code>.
</ins><br/>
 — Otherwise, <code>auto f = status(from)</code> and if needed <code>auto t = status(to)</code>.
</p>
</blockquote>





</body>
</html>
