Mailinglist Archive: zypp-commit (275 mails)

< Previous Next >
[zypp-commit] <libzypp> ma-misc : Add filesystem::hardlinkCopy: Create newpath as hardlink or copy of oldpath.
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Tue, 13 Oct 2009 13:11:06 +0200
  • Message-id: <E1N4M8l-0004k6-V0@xxxxxxxxxxxxxxxx>
ref: refs/heads/ma-misc
commit e7ecf4350561d9978c33139967183bb8b3c6bda0
Author: Michael Andres <ma@xxxxxxx>
Date: Tue Oct 13 13:11:06 2009 +0200

Add filesystem::hardlinkCopy: Create newpath as hardlink or copy of oldpath.
---
zypp/PathInfo.cc | 25 +++++++++++++++++++++++++
zypp/PathInfo.h | 7 +++++++
2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/zypp/PathInfo.cc b/zypp/PathInfo.cc
index c8ebe3d..25bec31 100644
--- a/zypp/PathInfo.cc
+++ b/zypp/PathInfo.cc
@@ -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
//
diff --git a/zypp/PathInfo.h b/zypp/PathInfo.h
index 2dbd19f..43376f8 100644
--- a/zypp/PathInfo.h
+++ b/zypp/PathInfo.h
@@ -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.
*
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages