Add filesystem::hardlinkCopy: Create newpath as hardlink or copy of oldpath.
authorMichael Andres <ma@suse.de>
Tue, 13 Oct 2009 11:11:06 +0000 (13:11 +0200)
committerMichael Andres <ma@suse.de>
Tue, 13 Oct 2009 11:11:06 +0000 (13:11 +0200)
zypp/PathInfo.cc
zypp/PathInfo.h

index c8ebe3d..25bec31 100644 (file)
@@ -812,6 +812,31 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
+    // METHOD NAME : hardlink
+    // METHOD TYPE : int
+    //
+    int hardlinkCopy( const Pathname & oldpath, const Pathname & newpath )
+    {
+      MIL << "hardlinkCopy " << oldpath << " -> " << newpath;
+      if ( ::link( oldpath.asString().c_str(), newpath.asString().c_str() ) == -1 )
+      {
+        switch ( errno )
+        {
+          case EEXIST: // newpath already exists
+            if ( unlink( newpath ) == 0 && ::link( oldpath.asString().c_str(), newpath.asString().c_str() ) != -1 )
+              return _Log_Result( 0 );
+            break;
+          case EXDEV: // oldpath  and  newpath are not on the same mounted file system
+            return copy( oldpath, newpath );
+            break;
+        }
+        return _Log_Result( errno );
+      }
+      return _Log_Result( 0 );
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    //
     // METHOD NAME : readlink
     // METHOD TYPE : int
     //
index 2dbd19f..43376f8 100644 (file)
@@ -606,6 +606,13 @@ namespace zypp
     int hardlink( const Pathname & oldpath, const Pathname & newpath );
 
     /**
+     * Create \a newpath as hardlink or copy of \a oldpath.
+     *
+     * @return 0 on success, errno on failure.
+     */
+    int hardlinkCopy( const Pathname & oldpath, const Pathname & newpath );
+
+    /**
      * Like '::readlink'. Return the contents of the symbolic link
      * \a symlink_r via \a target_r.
      *