- fixed filesystem::expandlink(Pathname) (bnc #368477)
authorJan Kupec <jkupec@suse.cz>
Wed, 30 Apr 2008 12:18:54 +0000 (12:18 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 30 Apr 2008 12:18:54 +0000 (12:18 +0000)
devel/devel.jkupec/CMakeLists.txt
devel/devel.jkupec/data/pathinfo/afile [new file with mode: 0644]
devel/devel.jkupec/data/pathinfo/alink [new symlink]
devel/devel.jkupec/data/pathinfo/subdir/anotherfile [new file with mode: 0644]
devel/devel.jkupec/data/pathinfo/subdirlink [new symlink]
devel/devel.jkupec/pathinfo.cc [new file with mode: 0644]
zypp/PathInfo.cc

index 01c33b8..ed324b8 100644 (file)
@@ -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 (file)
index 0000000..aeef426
--- /dev/null
@@ -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 (symlink)
index 0000000..6a93f4f
--- /dev/null
@@ -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 (file)
index 0000000..cdcb284
--- /dev/null
@@ -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 (symlink)
index 0000000..f57a792
--- /dev/null
@@ -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 (file)
index 0000000..40b97b5
--- /dev/null
@@ -0,0 +1,29 @@
+#include <iostream>
+
+#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;
+}
index 3b30186..c2b5875 100644 (file)
@@ -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;