From a6c8fb4b4238fc94202b8702e4e993f45a1d1e22 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 18 Oct 2011 11:02:32 +0200 Subject: [PATCH] PathInfo::hardlinkCopy: fix handling cross-device links --- zypp/PathInfo.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/zypp/PathInfo.cc b/zypp/PathInfo.cc index 5791f2ff3..486e0b18d 100644 --- a/zypp/PathInfo.cc +++ b/zypp/PathInfo.cc @@ -820,22 +820,26 @@ namespace zypp { MIL << "hardlinkCopy " << oldpath << " -> " << newpath; - PathInfo oldpi( oldpath, PathInfo::LSTAT ); - if ( oldpi.isLink() ) + PathInfo pi( oldpath, PathInfo::LSTAT ); + if ( pi.isLink() ) { - // dont hardlink symliknks! + // dont hardlink symlinks! return copy( oldpath, newpath ); } - // Here: no symlink + pi.lstat( newpath ); + if ( pi.isExist() ) + { + int res = unlink( newpath ); + if ( res != 0 ) + return _Log_Result( res ); + } + + // Here: no symlink, no 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; -- 2.34.1