Add PBD API to hard-link files
authorRobin Gareus <robin@gareus.org>
Mon, 12 Aug 2019 14:41:25 +0000 (16:41 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 12 Aug 2019 14:41:25 +0000 (16:41 +0200)
libs/pbd/file_utils.cc
libs/pbd/pbd/file_utils.h

index ef10c4566c75793870de03e4da3095d030ae5c70..8247530fe3dcf5129653afbf2d477aff531dd2ac 100644 (file)
@@ -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)
 {
index de573cd0e1138d76ea3b6c3a804397f29b9eecaf..b834587ae164127bb557f1cd68de28878c867b0c 100644 (file)
@@ -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