From 978a41defd35de060f2bfbd097beadf991170ee1 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Wed, 30 Apr 2008 12:18:54 +0000 Subject: [PATCH] - fixed filesystem::expandlink(Pathname) (bnc #368477) --- devel/devel.jkupec/CMakeLists.txt | 3 +++ devel/devel.jkupec/data/pathinfo/afile | 1 + devel/devel.jkupec/data/pathinfo/alink | 1 + .../devel.jkupec/data/pathinfo/subdir/anotherfile | 1 + devel/devel.jkupec/data/pathinfo/subdirlink | 1 + devel/devel.jkupec/pathinfo.cc | 29 ++++++++++++++++++++++ zypp/PathInfo.cc | 7 +++--- 7 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 devel/devel.jkupec/data/pathinfo/afile create mode 120000 devel/devel.jkupec/data/pathinfo/alink create mode 100644 devel/devel.jkupec/data/pathinfo/subdir/anotherfile create mode 120000 devel/devel.jkupec/data/pathinfo/subdirlink create mode 100644 devel/devel.jkupec/pathinfo.cc diff --git a/devel/devel.jkupec/CMakeLists.txt b/devel/devel.jkupec/CMakeLists.txt index 01c33b8..ed324b8 100644 --- a/devel/devel.jkupec/CMakeLists.txt +++ b/devel/devel.jkupec/CMakeLists.txt @@ -23,3 +23,6 @@ TARGET_LINK_LIBRARIES( bridge zypp ) ADD_EXECUTABLE( poolquery poolquery.cc ) TARGET_LINK_LIBRARIES( poolquery zypp ) + +ADD_EXECUTABLE( pathinfo pathinfo.cc ) +TARGET_LINK_LIBRARIES( pathinfo zypp ) diff --git a/devel/devel.jkupec/data/pathinfo/afile b/devel/devel.jkupec/data/pathinfo/afile new file mode 100644 index 0000000..aeef426 --- /dev/null +++ b/devel/devel.jkupec/data/pathinfo/afile @@ -0,0 +1 @@ +a file \ No newline at end of file diff --git a/devel/devel.jkupec/data/pathinfo/alink b/devel/devel.jkupec/data/pathinfo/alink new file mode 120000 index 0000000..6a93f4f --- /dev/null +++ b/devel/devel.jkupec/data/pathinfo/alink @@ -0,0 +1 @@ +afile \ No newline at end of file diff --git a/devel/devel.jkupec/data/pathinfo/subdir/anotherfile b/devel/devel.jkupec/data/pathinfo/subdir/anotherfile new file mode 100644 index 0000000..cdcb284 --- /dev/null +++ b/devel/devel.jkupec/data/pathinfo/subdir/anotherfile @@ -0,0 +1 @@ +another file \ No newline at end of file diff --git a/devel/devel.jkupec/data/pathinfo/subdirlink b/devel/devel.jkupec/data/pathinfo/subdirlink new file mode 120000 index 0000000..f57a792 --- /dev/null +++ b/devel/devel.jkupec/data/pathinfo/subdirlink @@ -0,0 +1 @@ +subdir/anotherfile \ No newline at end of file diff --git a/devel/devel.jkupec/pathinfo.cc b/devel/devel.jkupec/pathinfo.cc new file mode 100644 index 0000000..40b97b5 --- /dev/null +++ b/devel/devel.jkupec/pathinfo.cc @@ -0,0 +1,29 @@ +#include + +#include "zypp/Pathname.h" +#include "zypp/PathInfo.h" + +using std::cout; +using std::endl; +using std::string; +using namespace zypp; + +int main (int argc, const char ** argv) +{ + Pathname datadir(SRC_DIR "/data/pathinfo"); + Pathname alink = datadir / "alink"; + PathInfo alinkinfo(alink); + + cout << "alink exists: " << alinkinfo.isExist() << endl; + Pathname alinkExp = filesystem::expandlink(alink); + cout << "alink expands to: " << alinkExp << endl; + cout << "alinkExp exists: " << PathInfo(alinkExp).isExist() << endl; + + Pathname subdirlink = datadir / "subdirlink"; + PathInfo subdirlinkinfo(subdirlink); + + cout << "subdirlink exists: " << subdirlinkinfo.isExist() << endl; + Pathname subdirlinkExp = filesystem::expandlink(subdirlink); + cout << "subdirlink expands to: " << subdirlinkExp << endl; + cout << "subdirlinkExp exists: " << PathInfo(subdirlinkExp).isExist() << endl; +} diff --git a/zypp/PathInfo.cc b/zypp/PathInfo.cc index 3b30186..c2b5875 100644 --- a/zypp/PathInfo.cc +++ b/zypp/PathInfo.cc @@ -768,8 +768,9 @@ namespace zypp for (count = level_limit; info.isLink() && count; count--) { - DBG << "following symlink " << path << std::endl; - path = readlink(path); + DBG << "following symlink " << path; + path = path.dirname() / readlink(path); + DBG << "->" << path << std::endl; info = PathInfo(path, PathInfo::LSTAT); } @@ -785,7 +786,7 @@ namespace zypp // check for a broken link if (PathInfo(path).isExist()) return path; - // broken link, return and empty path + // broken link, return an empty path else { ERR << path << " is broken (expanded from " << path_r << ")" << endl; -- 2.7.4