diff options
-rw-r--r-- | libs/ardour/ardour/utils.h | 1 | ||||
-rw-r--r-- | libs/ardour/file_source.cc | 3 | ||||
-rw-r--r-- | libs/ardour/session.cc | 4 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 2 | ||||
-rw-r--r-- | libs/ardour/utils.cc | 12 | ||||
-rw-r--r-- | libs/pbd/filesystem.cc | 33 | ||||
-rw-r--r-- | libs/pbd/pbd/filesystem.h | 4 | ||||
-rw-r--r-- | libs/pbd/wscript | 1 |
8 files changed, 43 insertions, 17 deletions
diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index 7eba3fa18c..5052f03bab 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -61,7 +61,6 @@ std::string path_expand (std::string); /* single file path */ std::string search_path_expand (std::string); /* colon-separated search path */ std::string region_name_from_path (std::string path, bool strip_channels, bool add_channel_suffix = false, uint32_t total = 0, uint32_t this_one = 0); bool path_is_paired (std::string path, std::string& pair_base); -bool inodes_same (const std::string &, const std::string &); void compute_equal_power_fades (ARDOUR::framecnt_t nframes, float* in, float* out); diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc index fd3e9ef142..f4f3c40d9d 100644 --- a/libs/ardour/file_source.cc +++ b/libs/ardour/file_source.cc @@ -33,6 +33,7 @@ #include "pbd/strsplit.h" #include "pbd/shortpath.h" #include "pbd/enumwriter.h" +#include "pbd/filesystem.h" #include <glibmm/miscutils.h> #include <glibmm/fileutils.h> @@ -277,7 +278,7 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist ++j; while (j != hits.end()) { - if (inodes_same (*i, *j)) { + if (PBD::sys::inodes_same (*i, *j)) { /* *i and *j are the same file; break out of the loop early */ break; } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 37d4d2908f..fdddb3b2c2 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4478,7 +4478,7 @@ Session::ensure_search_path_includes (const string& path, DataType type) search_path = config.get_midi_search_path (); break; } - + split (search_path, dirs, ':'); for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) { @@ -4488,7 +4488,7 @@ Session::ensure_search_path_includes (const string& path, DataType type) On Windows, I think we could just do if (*i == path) here. */ - if (inodes_same (*i, path)) { + if (PBD::sys::inodes_same (*i, path)) { return; } } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 4b40a80d80..e729a7b00d 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -428,7 +428,7 @@ bool Session::path_is_within_session (const std::string& path) { for (vector<space_and_path>::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { - if (path.find ((*i).path) == 0) { + if (PBD::sys::path_is_within (i->path, path)) { return true; } } diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index beb003e713..8ab20ecc62 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -745,18 +745,6 @@ double slider_position_to_gain_with_max (double g, double max_gain) return slider_position_to_gain (g * max_gain/2.0); } -/** @return true if files a and b have the same inode */ -bool -inodes_same (const string& a, const string& b) -{ - struct stat bA; - int const rA = stat (a.c_str(), &bA); - struct stat bB; - int const rB = stat (b.c_str(), &bB); - - return (rA == 0 && rB == 0 && bA.st_ino == bB.st_ino); -} - extern "C" { void c_stacktrace() { stacktrace (cerr); } } diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc index a4bf781802..819a044a7b 100644 --- a/libs/pbd/filesystem.cc +++ b/libs/pbd/filesystem.cc @@ -254,6 +254,39 @@ get_absolute_path (const path & p) return f->get_path (); } +/** @return true if a and b have the same inode */ +bool +inodes_same (const path& a, const path& b) +{ + struct stat bA; + int const rA = stat (a.to_string().c_str(), &bA); + struct stat bB; + int const rB = stat (b.to_string().c_str(), &bB); + + return (rA == 0 && rB == 0 && bA.st_ino == bB.st_ino); +} + +/** Find out if `needle' is a file or directory within the + * directory `haystack'. + * @return true if it is. + */ +bool +path_is_within (path const & haystack, path needle) +{ + while (1) { + if (inodes_same (haystack, needle)) { + return true; + } + + needle = needle.branch_path (); + if (needle.to_string().empty() || needle.to_string() == "/") { + break; + } + } + + return false; +} + } // namespace sys } // namespace PBD diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h index e8073adf0e..1fb6fbc155 100644 --- a/libs/pbd/pbd/filesystem.h +++ b/libs/pbd/pbd/filesystem.h @@ -205,6 +205,10 @@ std::string extension (const path& p); path get_absolute_path (const path &); +bool path_is_within (const path &, path); + +bool inodes_same (const path &, const path &); + } // namespace sys } // namespace PBD diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 83a78f8ef0..da0f9c0dd1 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -139,6 +139,7 @@ def build(bld): test/scalar_properties.cc test/signals_test.cc test/convert_test.cc + test/filesystem_test.cc '''.split() testobj.target = 'run-tests' testobj.includes = obj.includes + ['test', '../pbd'] |