diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-07-22 14:52:05 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-07-22 14:52:05 +0000 |
commit | 1c1b359ff21aac57bd71d291049d657f66cf31f5 (patch) | |
tree | b05cc2756c2ec751fd0567d7b7ffb0baa8c1767f /libs/ardour/utils.cc | |
parent | 5c17bd3df225b958c2f8510ff03d38bbb513c150 (diff) |
second (and hopefully) final part of changes to respond to header format changes sensibly: lookup existing files correctly, and don't end up with gapped "take" numbers for successive files since we now remove ::removable() sources when switching to new ones (for audio)
git-svn-id: svn://localhost/ardour2/branches/3.0@7470 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/utils.cc')
-rw-r--r-- | libs/ardour/utils.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index abdba63803..66835dc1b2 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -35,7 +35,10 @@ #include <sys/stat.h> #include <sys/time.h> #include <fcntl.h> -#include <unistd.h> +#include <dirent.h> +#include <errno.h> + +#include <glibmm/miscutils.h> #ifdef HAVE_WORDEXP #include <wordexp.h> @@ -538,6 +541,51 @@ native_header_format_extension (HeaderFormat hf, const DataType& type) return ".wav"; } +bool +matching_unsuffixed_filename_exists_in (const string& dir, const string& path) +{ + string bws = basename_nosuffix (path); + struct dirent* dentry; + struct stat statbuf; + DIR* dead; + bool ret = false; + + if ((dead = ::opendir (dir.c_str())) == 0) { + error << string_compose (_("cannot open directory %1 (%2)"), dir, strerror (errno)) << endl; + return false; + } + + while ((dentry = ::readdir (dead)) != 0) { + + /* avoid '.' and '..' */ + + if ((dentry->d_name[0] == '.' && dentry->d_name[1] == '\0') || + (dentry->d_name[2] == '\0' && dentry->d_name[0] == '.' && dentry->d_name[1] == '.')) { + continue; + } + + string fullpath = Glib::build_filename (dir, dentry->d_name); + + if (::stat (fullpath.c_str(), &statbuf)) { + continue; + } + + if (!S_ISREG (statbuf.st_mode)) { + continue; + } + + string bws2 = basename_nosuffix (dentry->d_name); + + if (bws2 == bws) { + ret = true; + break; + } + } + + ::closedir (dead); + return ret; +} + extern "C" { void c_stacktrace() { stacktrace (cerr); } } |