aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-17 02:04:42 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-17 02:04:42 +0000
commit1b29133a5c98125521ef50d42807c7ff6938524c (patch)
treeb2bfe79c975d5ae5623c7985066302f220ec6f22
parentd1472a68bec64eaf211ea5d8f7194830c716addd (diff)
downloadpaludis-1b29133a5c98125521ef50d42807c7ff6938524c.tar.gz
paludis-1b29133a5c98125521ef50d42807c7ff6938524c.tar.xz
Add FSEntry::realpath()
-rw-r--r--paludis/Makefile.am.m410
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/fs_entry.cc13
-rw-r--r--paludis/fs_entry.hh5
-rw-r--r--paludis/fs_entry_TEST.cc25
-rwxr-xr-xpaludis/fs_entry_TEST_cleanup.sh9
-rwxr-xr-xpaludis/fs_entry_TEST_setup.sh9
7 files changed, 67 insertions, 6 deletions
diff --git a/paludis/Makefile.am.m4 b/paludis/Makefile.am.m4
index df69f74..b1aa88a 100644
--- a/paludis/Makefile.am.m4
+++ b/paludis/Makefile.am.m4
@@ -5,10 +5,12 @@ dnl vim: set ft=m4 et :
define(`filelist', `')dnl
define(`testlist', `')dnl
-define(`addtest', `define(`testlist', testlist `$1_TEST')
+define(`testscriptlist', `')dnl
+define(`addtest', `define(`testlist', testlist `$1_TEST')dnl
$1_TEST_SOURCES = $1_TEST.cc
$1_TEST_LDADD = $(top_builddir)/test/libtest.a libpaludis.a
')dnl
+define(`addtestscript', `define(`testscriptlist', testscriptlist `$1_TEST_setup.sh $1_TEST_cleanup.sh')')dnl
define(`addhh', `define(`filelist', filelist `$1.hh')')dnl
define(`addcc', `define(`filelist', filelist `$1.cc')')dnl
define(`addimpl', `define(`filelist', filelist `$1-impl.hh')')dnl
@@ -16,7 +18,8 @@ define(`addthis', `dnl
ifelse(`$2', `hh', `addhh(`$1')', `')dnl
ifelse(`$2', `cc', `addcc(`$1')', `')dnl
ifelse(`$2', `impl', `addimpl(`$1')', `')dnl
-ifelse(`$2', `test', `addtest(`$1')', `')')dnl
+ifelse(`$2', `test', `addtest(`$1')', `')dnl
+ifelse(`$2', `testscript', `addtestscript(`$1')', `')')dnl
define(`add', `addthis(`$1',`$2')addthis(`$1',`$3')addthis(`$1',`$4')dnl
addthis(`$1',`$5')addthis(`$1',`$6')')dnl
@@ -26,7 +29,8 @@ CLEANFILES = *~
MAINTAINERCLEANFILES = Makefile.in Makefile.am about.hh paludis.hh smart_record.hh comparison_policy.hh
AM_CXXFLAGS = -I$(top_srcdir)
DEFS=-DSYSCONFDIR=\"$(sysconfdir)\"
-EXTRA_DIST = about.hh.in Makefile.am.m4 paludis.hh.m4 files.m4 smart_record.hh.m4 comparison_policy.hh.m4
+EXTRA_DIST = about.hh.in Makefile.am.m4 paludis.hh.m4 files.m4 smart_record.hh.m4 comparison_policy.hh.m4 \
+ testscriptlist
SUBDIRS = . args
libpaludis_a_SOURCES = filelist
diff --git a/paludis/files.m4 b/paludis/files.m4
index 444f877..e372005 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -50,7 +50,7 @@ add(`environment', `hh', `cc')
add(`exception', `hh', `cc')
add(`fake_repository', `hh', `cc')
add(`filter_insert_iterator', `hh', `cc', `test')
-add(`fs_entry', `hh', `cc', `test')
+add(`fs_entry', `hh', `cc', `test', `testscript')
add(`fs_error', `hh', `cc')
add(`getenv', `hh', `cc', `test')
add(`indirect_iterator', `hh', `cc', `test')
diff --git a/paludis/fs_entry.cc b/paludis/fs_entry.cc
index f6e49e9..bd9f3ec 100644
--- a/paludis/fs_entry.cc
+++ b/paludis/fs_entry.cc
@@ -26,6 +26,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
+#include <limits.h>
+#include <cstring>
+#include <cstdlib>
/** \file
* Implementation of paludis::FSEntry.
@@ -168,6 +171,16 @@ FSEntry::basename() const
return _path.substr(_path.rfind('/') + 1);
}
+FSEntry
+FSEntry::realpath() const
+{
+ char r[PATH_MAX + 1];
+ std::memset(r, 0, PATH_MAX + 1);
+ if (! ::realpath(_path.c_str(), r))
+ throw FSError("Could not resolve path '" + _path + "'");
+ return FSEntry(r);
+}
+
std::ostream &
paludis::operator<< (std::ostream & s, const FSEntry & f)
{
diff --git a/paludis/fs_entry.hh b/paludis/fs_entry.hh
index 466fa94..263acdf 100644
--- a/paludis/fs_entry.hh
+++ b/paludis/fs_entry.hh
@@ -120,6 +120,11 @@ namespace paludis
* Return the last part of our path (eg '/foo/bar' => 'bar').
*/
std::string basename() const;
+
+ /**
+ * Return the canonicalised version of our path.
+ */
+ FSEntry realpath() const;
};
/**
diff --git a/paludis/fs_entry_TEST.cc b/paludis/fs_entry_TEST.cc
index b2e1dd0..1f25b79 100644
--- a/paludis/fs_entry_TEST.cc
+++ b/paludis/fs_entry_TEST.cc
@@ -37,9 +37,9 @@ namespace test_cases
/**
* \test Test FSEntry construction and manipulation.
*/
- struct TestFSEntryManipulation : TestCase
+ struct FSEntryManipulationTest : TestCase
{
- TestFSEntryManipulation() : TestCase("construction and manipulation") { }
+ FSEntryManipulationTest() : TestCase("construction and manipulation") { }
void run()
{
@@ -58,4 +58,25 @@ namespace test_cases
TEST_CHECK_EQUAL(c, FSEntry("/foo/bar/moo"));
}
} test_fs_entry_manipulation;
+
+ /**
+ * \test Test FSEntry realpath.
+ */
+ struct FSEntryRealpathTest : TestCase
+ {
+ FSEntryRealpathTest() : TestCase("realpath") { }
+
+ void run()
+ {
+ FSEntry d("fs_entry_TEST_dir");
+ TEST_CHECK(d.is_directory());
+
+ FSEntry f("fs_entry_TEST_dir/symlink_to_dir_a/file_in_a");
+ TEST_CHECK(f.is_regular_file());
+ FSEntry r(f.realpath());
+ TEST_CHECK(r.is_regular_file());
+ std::string e("fs_entry_TEST_dir/dir_a/file_in_a");
+ TEST_CHECK_EQUAL(std::string(r).substr(std::string(r).length() - e.length()), e);
+ }
+ } test_fs_entry_realpath;
}
diff --git a/paludis/fs_entry_TEST_cleanup.sh b/paludis/fs_entry_TEST_cleanup.sh
new file mode 100755
index 0000000..894b1f7
--- /dev/null
+++ b/paludis/fs_entry_TEST_cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d fs_entry_TEST_dir ] ; then
+ rm -fr fs_entry_TEST_dir
+else
+ true
+fi
+
diff --git a/paludis/fs_entry_TEST_setup.sh b/paludis/fs_entry_TEST_setup.sh
new file mode 100755
index 0000000..2d98823
--- /dev/null
+++ b/paludis/fs_entry_TEST_setup.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir fs_entry_TEST_dir || exit 2
+cd fs_entry_TEST_dir || exit 3
+mkdir dir_a || exit 4
+ln -s dir_a symlink_to_dir_a || exit 5
+touch dir_a/file_in_a || exit 6
+