[vlmc-devel] commit: Workspace: If possible, create a hard link instead of copying. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Jun 28 00:57:05 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Mon Jun 28 00:20:35 2010 +0200| [fd173bffacfbb4e55a96e190eb175149d3dbdff4] | committer: Hugo Beauzée-Luyssen 

Workspace: If possible, create a hard link instead of copying.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=fd173bffacfbb4e55a96e190eb175149d3dbdff4
---

 src/Project/WorkspaceWorker.cpp |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/Project/WorkspaceWorker.cpp b/src/Project/WorkspaceWorker.cpp
index d1af1ba..21e2f0d 100644
--- a/src/Project/WorkspaceWorker.cpp
+++ b/src/Project/WorkspaceWorker.cpp
@@ -25,6 +25,7 @@
 #include "Media.h"
 #include "SettingsManager.h"
 
+#include <cerrno>
 #include <QFile>
 #include <QFileInfo>
 
@@ -39,11 +40,30 @@ WorkspaceWorker::WorkspaceWorker( Media *media ) :
 void
 WorkspaceWorker::run()
 {
-    QFile           file( m_media->fileInfo()->absoluteFilePath() );
     const QString   &projectPath = VLMC_PROJECT_GET_STRING( "general/Workspace" );
     const QString   dest = projectPath + '/' + m_media->fileInfo()->fileName();
+    bool            hardLinkOk = false;
 
-    file.copy( m_media->fileInfo()->absoluteFilePath(), dest );
-    qDebug() << "Media copied to:" << dest;
+#ifdef Q_OS_UNIX
+    if ( link( m_media->fileInfo()->absoluteFilePath().toStdString().c_str(),
+          dest.toStdString().c_str() ) < 0 )
+    {
+        qDebug() << "Can't create hard link:" << strerror(errno) << "falling back to"
+                " hard copy mode.";
+    }
+    else
+    {
+        qDebug() << "Media hard linked to:" << dest;
+        hardLinkOk = true;
+    }
+#endif
+
+    if ( hardLinkOk == false )
+    {
+        QFile           file( m_media->fileInfo()->absoluteFilePath() );
+
+        file.copy( m_media->fileInfo()->absoluteFilePath(), dest );
+        qDebug() << "Media copied to:" << dest;
+    }
     emit copied( m_media, dest );
 }



More information about the Vlmc-devel mailing list