Skip to content
Snippets Groups Projects
Commit df4f2e76 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

fileutils: handle more cases in createFileLink

* handle case where linkFile == target
* hanlde case where linkFile already exists
* keep link if it already points to target

Change-Id: I01bd866332a29847d787cf55c6d1b8925c02b41a
parent 3f088fa8
Branches
No related tags found
No related merge requests found
......@@ -195,6 +195,14 @@ createHardlink(const std::filesystem::path& linkFile, const std::filesystem::pat
bool
createFileLink(const std::filesystem::path& linkFile, const std::filesystem::path& target, bool hard)
{
if (linkFile == target)
return true;
std::error_code ec;
if (std::filesystem::exists(linkFile, ec)) {
if (std::filesystem::is_symlink(linkFile, ec) && std::filesystem::read_symlink(linkFile, ec) == target)
return true;
std::filesystem::remove(linkFile, ec);
}
if (not hard or not createHardlink(linkFile, target))
return createSymlink(linkFile, target);
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment