Skip to content

Latest commit

 

History

History
76 lines (59 loc) · 2.78 KB

copy_symlink.md

File metadata and controls

76 lines (59 loc) · 2.78 KB

copy_symlink

  • filesystem[meta header]
  • std::filesystem[meta namespace]
  • function[meta id-type]
  • cpp17[meta cpp]
namespace std::filesystem {
  void copy_symlink(const path& existing_symlink, const path& new_symlink); // (1)
  void copy_symlink(const path& existing_symlink, const path& new_symlink,
                    std::error_code& ec) noexcept;                          // (2)
}
  • path[link path.md]

概要

シンボリックリンクをコピーする。

パスexisting_symlinkにあるファイル・ディレクトリへのシンボリックリンクが指すパスへのシンボリックリンクを、new_symlinkに作成する。

効果

  • パスexisting_sumlinkがシンボリックリンクに解決され、
  • シンボリックリンク以外のファイルの場合はエラー

例外

  • (1) : ファイルシステムがエラーを報告する場合がある。パスexisting_symlinkがシンボリックリンクに解決されない場合もエラーである。エラーが発生した場合は、std::filesystem::filesystem_error例外を送出する
  • (2) : 投げない

#include <cassert>
#include <filesystem>
#include <fstream>

namespace fs = std::filesystem;

int main()
{
  std::ofstream{"regular.txt"};
  fs::create_symlink("regular.txt", "regular.symlink");

  fs::copy_symlink("regular.symlink", "copied.symlink");

  assert(fs::exists("regular.symlink"));
  assert(fs::exists("copied.symlink"));

  assert(fs::read_symlink("regular.symlink") == "regular.txt");
  assert(fs::read_symlink("copied.symlink") == "regular.txt");
}
  • fs::copy_symlink[color ff0000]
  • fs::create_symlink[link create_symlink.md]
  • fs::exists[link exists.md]
  • fs::read_symlink[link read_symlink.md]

出力

バージョン

言語

  • C++17

処理系