From e0b126d8c7f691856ec4d80bb57cb1ba5c71fd69 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 22 Jun 2016 23:00:36 +0300 Subject: Add mkslink(), mkhlink() --- butl/filesystem.cxx | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) (limited to 'butl/filesystem.cxx') diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx index a2d6434..c3d21cd 100644 --- a/butl/filesystem.cxx +++ b/butl/filesystem.cxx @@ -4,18 +4,23 @@ #include -#include // errno, E* -#include // stat, rmdir(), unlink() -#include // stat -#include // stat(), lstat(), S_IS*, mkdir() - #ifndef _WIN32 # include // struct dirent, *dir() +# include // symlink(), link() #else -# include // _find*() -# include // _mkdir() +# include + +# include // _find*() +# include // _mkdir() + +# include #endif +#include // errno, E* +#include // stat, rmdir(), unlink() +#include // stat +#include // stat(), lstat(), S_IS*, mkdir() + #include // unique_ptr #include @@ -152,6 +157,48 @@ namespace butl return r; } +#ifndef _WIN32 + void + mksymlink (const path& target, const path& link, bool) + { + if (symlink (target.string ().c_str (), link.string ().c_str ()) == -1) + throw system_error (errno, system_category ()); + } + + void + mkhardlink (const path& target, const path& link, bool) + { + if (::link (target.string ().c_str (), link.string ().c_str ()) == -1) + throw system_error (errno, system_category ()); + } + +#else + + void + mksymlink (const path&, const path&, bool) + { + throw system_error (ENOSYS, system_category (), "symlinks not supported"); + } + + void + mkhardlink (const path& target, const path& link, bool dir) + { + if (!dir) + { + if (!CreateHardLinkA (link.string ().c_str (), + target.string ().c_str (), + nullptr)) + { + string e (win32::last_error_msg ()); + throw system_error (EIO, system_category (), e); + } + } + else + throw system_error ( + ENOSYS, system_category (), "directory hard links not supported"); + } +#endif + // Figuring out whether we have the nanoseconds in struct stat. Some // platforms (e.g., FreeBSD), may provide some "compatibility" #define's, // so use the second argument to not end up with the same signatures. -- cgit v1.1