summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-08-12 16:41:25 +0200
committerRobin Gareus <robin@gareus.org>2019-08-12 16:41:25 +0200
commitffbf40c3d1d5ff12ddc6b48c0b96204f8bb249f0 (patch)
treebe19669ecab97e989cd09b700f6694d56f87cc24 /libs
parentc0f0acaa9fd4c302e1f499560233fe20174b95f7 (diff)
Add PBD API to hard-link files
Diffstat (limited to 'libs')
-rw-r--r--libs/pbd/file_utils.cc11
-rw-r--r--libs/pbd/pbd/file_utils.h5
2 files changed, 16 insertions, 0 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc
index ef10c4566c..8247530fe3 100644
--- a/libs/pbd/file_utils.cc
+++ b/libs/pbd/file_utils.cc
@@ -356,6 +356,17 @@ touch_file (const std::string& path)
return false;
}
+bool
+hard_link (const std::string& existing_file, const std::string& new_path)
+{
+#ifdef PLATFORM_WINDOWS
+ /* see also ntfs_link -- msvc only pbd extension */
+ return CreateHardLinkA (new_path.c_str(), existing_file.c_str(), NULL);
+#else
+ return 0 == link (existing_file.c_str(), new_path.c_str());
+#endif
+}
+
std::string
get_absolute_path (const std::string & p)
{
diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h
index de573cd0e1..b834587ae1 100644
--- a/libs/pbd/pbd/file_utils.h
+++ b/libs/pbd/pbd/file_utils.h
@@ -190,6 +190,11 @@ LIBPBD_API void copy_recurse(const std::string & from_path, const std::string &
*/
LIBPBD_API bool touch_file (const std::string& path);
+/** try hard-link a file
+ * @return true if file was successfully linked
+ */
+LIBPBD_API bool hard_link (const std::string& existing_file, const std::string& new_path);
+
/**
* Take a (possibly) relative path and make it absolute
* @return An absolute path