diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2012-06-23 05:08:14 +0000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2012-06-23 05:08:14 +0000 |
commit | e26e59b00634d5a66f39e40dea71d56a8dea0f2a (patch) | |
tree | 2fa3c913ba58d1189fb97d6057508e2566631475 /libs/pbd | |
parent | 6aee53710916320742370354c0867004166c6dab (diff) |
Move three file utility functions from pbd/filesystem.h to pbd/file_utils.h
git-svn-id: svn://localhost/ardour2/branches/3.0@12863 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/file_utils.cc | 38 | ||||
-rw-r--r-- | libs/pbd/filesystem.cc | 35 | ||||
-rw-r--r-- | libs/pbd/pbd/file_utils.h | 22 | ||||
-rw-r--r-- | libs/pbd/pbd/filesystem.h | 22 | ||||
-rw-r--r-- | libs/pbd/test/filesystem_test.cc | 25 |
5 files changed, 73 insertions, 69 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index f323ebcb69..31db84e88f 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -19,6 +19,9 @@ #include <algorithm> +#include <glib.h> +#include <glib/gstdio.h> + #include <glibmm/fileutils.h> #include <glibmm/miscutils.h> #include <glibmm/pattern.h> @@ -169,4 +172,39 @@ copy_files(const std::string & from_path, const std::string & to_dir) } } +std::string +get_absolute_path (const std::string & p) +{ + Glib::RefPtr<Gio::File> f = Gio::File::create_for_path (p); + return f->get_path (); +} + +bool +equivalent_paths (const std::string& a, const std::string& b) +{ + struct stat bA; + int const rA = g_stat (a.c_str(), &bA); + struct stat bB; + int const rB = g_stat (b.c_str(), &bB); + + return (rA == 0 && rB == 0 && bA.st_dev == bB.st_dev && bA.st_ino == bB.st_ino); +} + +bool +path_is_within (std::string const & haystack, std::string needle) +{ + while (1) { + if (equivalent_paths (haystack, needle)) { + return true; + } + + needle = Glib::path_get_dirname (needle); + if (needle == "." || needle == "/") { + break; + } + } + + return false; +} + } // namespace PBD diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc index 4e39374b98..e2b8b37ba7 100644 --- a/libs/pbd/filesystem.cc +++ b/libs/pbd/filesystem.cc @@ -211,41 +211,6 @@ extension (const path & p) } -std::string -get_absolute_path (const std::string & p) -{ - Glib::RefPtr<Gio::File> f = Gio::File::create_for_path (p); - return f->get_path (); -} - -bool -equivalent_paths (const std::string& a, const std::string& b) -{ - struct stat bA; - int const rA = g_stat (a.c_str(), &bA); - struct stat bB; - int const rB = g_stat (b.c_str(), &bB); - - return (rA == 0 && rB == 0 && bA.st_dev == bB.st_dev && bA.st_ino == bB.st_ino); -} - -bool -path_is_within (std::string const & haystack, std::string needle) -{ - while (1) { - if (equivalent_paths (haystack, needle)) { - return true; - } - - needle = Glib::path_get_dirname (needle); - if (needle == "." || needle == "/") { - break; - } - } - - return false; -} - } // namespace sys } // namespace PBD diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h index 475ddb9828..184e644bba 100644 --- a/libs/pbd/pbd/file_utils.h +++ b/libs/pbd/pbd/file_utils.h @@ -105,6 +105,28 @@ bool copy_file(const std::string & from_path, const std::string & to_path); */ void copy_files(const std::string & from_path, const std::string & to_dir); +/** + * Take a (possibly) relative path and make it absolute + * @return An absolute path + */ +std::string get_absolute_path (const std::string &); + +/** + * Find out if `needle' is a file or directory within the + * directory `haystack'. + * @return true if it is. + */ +bool path_is_within (const std::string &, std::string); + +/** + * @return true if p1 and p2 both resolve to the same file + * @param p1 a file path. + * @param p2 a file path. + * + * Uses g_stat to check for identical st_dev and st_ino values. + */ +bool equivalent_paths (const std::string &p1, const std::string &p2); + } // namespace PBD #endif diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h index f09c400f2e..74baaa3707 100644 --- a/libs/pbd/pbd/filesystem.h +++ b/libs/pbd/pbd/filesystem.h @@ -188,28 +188,6 @@ std::string basename (const path& p); */ std::string extension (const path& p); -/** - * Take a (possibly) relative path and make it absolute - * @return An absolute path - */ -std::string get_absolute_path (const std::string &); - -/** - * Find out if `needle' is a file or directory within the - * directory `haystack'. - * @return true if it is. - */ -bool path_is_within (const std::string &, std::string); - -/** - * @return true if p1 and p2 both resolve to the same file - * @param p1 a file path. - * @param p2 a file path. - * - * Uses g_stat to check for identical st_dev and st_ino values. - */ -bool equivalent_paths (const std::string &p1, const std::string &p2); - } // namespace sys } // namespace PBD diff --git a/libs/pbd/test/filesystem_test.cc b/libs/pbd/test/filesystem_test.cc index 11371c8cb6..38c985d122 100644 --- a/libs/pbd/test/filesystem_test.cc +++ b/libs/pbd/test/filesystem_test.cc @@ -1,6 +1,7 @@ #include <unistd.h> #include <stdlib.h> #include "filesystem_test.h" +#include "pbd/file_utils.h" #include "pbd/filesystem.h" using namespace std; @@ -13,23 +14,23 @@ FilesystemTest::testPathIsWithin () system ("rm -r foo"); PBD::sys::create_directories ("foo/bar/baz"); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar/baz", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar", "foo/bar")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar/baz", "frobozz") == false); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "frobozz") == false); int const r = symlink ("bar", "foo/jim"); CPPUNIT_ASSERT (r == 0); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar/baz", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar", "foo/bar/baz")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/bar", "foo/bar")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar/baz", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar/baz")); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/bar", "foo/bar")); - CPPUNIT_ASSERT (PBD::sys::path_is_within ("foo/jim/baz", "frobozz") == false); + CPPUNIT_ASSERT (PBD::path_is_within ("foo/jim/baz", "frobozz") == false); } |