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);
#include "pbd/strsplit.h"
#include "pbd/shortpath.h"
#include "pbd/enumwriter.h"
+#include "pbd/filesystem.h"
#include <glibmm/miscutils.h>
#include <glibmm/fileutils.h>
++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;
}
search_path = config.get_midi_search_path ();
break;
}
-
+
split (search_path, dirs, ':');
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
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;
}
}
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;
}
}
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); }
}
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
path get_absolute_path (const path &);
+bool path_is_within (const path &, path);
+
+bool inodes_same (const path &, const path &);
+
} // namespace sys
} // namespace PBD
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']