summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-07-11 14:57:16 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-07-11 14:57:16 -0400
commit09e471545bd1c41f474e733cc404867d87e87d49 (patch)
treed58274312a20b08b3b99fcea99f9a0c00998ce31
parent2ddab2d2f6738f9c1dc0dd31a12cdeb6b7fe540e (diff)
remove direct of realpath(2), replace with canonical_path() which is a no-op on windows
-rw-r--r--gtk2_ardour/main.cc3
-rw-r--r--libs/ardour/find_session.cc9
-rw-r--r--libs/ardour/session_state.cc30
-rw-r--r--libs/pbd/pathexpand.cc27
-rw-r--r--libs/pbd/pbd/pathexpand.h1
5 files changed, 31 insertions, 39 deletions
diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc
index cd26a8cf8f..01678ed080 100644
--- a/gtk2_ardour/main.cc
+++ b/gtk2_ardour/main.cc
@@ -31,6 +31,7 @@
#include "pbd/file_utils.h"
#include "pbd/textreceiver.h"
#include "pbd/failed_constructor.h"
+#include "pbd/pathexpand.h"
#include "pbd/pthread_utils.h"
#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
#include "pbd/boost_debug.h"
@@ -277,7 +278,7 @@ fixup_bundle_environment (int /*argc*/, char* argv[])
lpath.push_back (dir_path);
lpath.push_back ("share");
lpath.push_back ("locale");
- localedir = realpath (Glib::build_filename (lpath).c_str(), NULL);
+ localedir = canonical_path (Glib::build_filename (lpath)).c_str();
}
#endif
diff --git a/libs/ardour/find_session.cc b/libs/ardour/find_session.cc
index f0a034d8d4..afcbe7393b 100644
--- a/libs/ardour/find_session.cc
+++ b/libs/ardour/find_session.cc
@@ -27,6 +27,7 @@
#include <glibmm/miscutils.h>
#include "pbd/compose.h"
+#include "pbd/pathexpand.h"
#include "pbd/error.h"
#include "ardour/filename_extensions.h"
@@ -43,16 +44,10 @@ int
find_session (string str, string& path, string& snapshot, bool& isnew)
{
struct stat statbuf;
- char buf[PATH_MAX+1];
isnew = false;
- if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) {
- error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg;
- return -1;
- }
-
- str = buf;
+ str = canonical_path (str);
/* check to see if it exists, and what it is */
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index ff7da665ed..d3c73d99e4 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -64,6 +64,7 @@
#include "pbd/enumwriter.h"
#include "pbd/error.h"
#include "pbd/file_utils.h"
+#include "pbd/pathexpand.h"
#include "pbd/pathscanner.h"
#include "pbd/pthread_utils.h"
#include "pbd/stacktrace.h"
@@ -128,14 +129,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
throw failed_constructor();
}
- char buf[PATH_MAX+1];
- if (!realpath (fullpath.c_str(), buf) && (errno != ENOENT)) {
- error << string_compose(_("Could not use path %1 (%2)"), buf, strerror(errno)) << endmsg;
- destroy ();
- throw failed_constructor();
- }
-
- _path = string(buf);
+ _path = canonical_path (fullpath);
if (_path[_path.length()-1] != G_DIR_SEPARATOR) {
_path += G_DIR_SEPARATOR;
@@ -2664,6 +2658,8 @@ Session::cleanup_sources (CleanupReport& rep)
bool used;
string spath;
int ret = -1;
+ string tmppath1;
+ string tmppath2;
_state_of_the_state = (StateOfTheState) (_state_of_the_state | InCleanup);
@@ -2788,9 +2784,6 @@ Session::cleanup_sources (CleanupReport& rep)
i = tmp;
}
- char tmppath1[PATH_MAX+1];
- char tmppath2[PATH_MAX+1];
-
if (candidates) {
for (vector<string*>::iterator x = candidates->begin(); x != candidates->end(); ++x) {
@@ -2799,19 +2792,10 @@ Session::cleanup_sources (CleanupReport& rep)
for (set<string>::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
- if (realpath(spath.c_str(), tmppath1) == 0) {
- error << string_compose (_("Cannot expand path %1 (%2)"),
- spath, strerror (errno)) << endmsg;
- continue;
- }
-
- if (realpath((*i).c_str(), tmppath2) == 0) {
- error << string_compose (_("Cannot expand path %1 (%2)"),
- (*i), strerror (errno)) << endmsg;
- continue;
- }
+ tmppath1 = canonical_path (spath);
+ tmppath2 = canonical_path ((*i));
- if (strcmp(tmppath1, tmppath2) == 0) {
+ if (tmppath1 == tmppath2) {
used = true;
break;
}
diff --git a/libs/pbd/pathexpand.cc b/libs/pbd/pathexpand.cc
index 4911f12788..ad53bea37b 100644
--- a/libs/pbd/pathexpand.cc
+++ b/libs/pbd/pathexpand.cc
@@ -18,8 +18,10 @@
*/
#include <vector>
-#include <climits>
#include <iostream>
+#include <climits>
+#include <cerrno>
+#include <cstdlib>
#include <regex.h>
@@ -32,6 +34,21 @@ using std::string;
using std::vector;
string
+PBD::canonical_path (const std::string& path)
+{
+#ifdef WIN32
+ return path;
+#endif
+ char buf[PATH_MAX+1];
+
+ if (!realpath (path.c_str(), buf) && (errno != ENOENT)) {
+ return path;
+ }
+
+ return string (buf);
+}
+
+string
PBD::path_expand (string path)
{
if (path.empty()) {
@@ -97,13 +114,7 @@ PBD::path_expand (string path)
/* canonicalize */
- char buf[PATH_MAX+1];
-
- if (realpath (path.c_str(), buf)) {
- return buf;
- } else {
- return string();
- }
+ return canonical_path (path);
}
string
diff --git a/libs/pbd/pbd/pathexpand.h b/libs/pbd/pbd/pathexpand.h
index a7b9f7557a..2b2639e07e 100644
--- a/libs/pbd/pbd/pathexpand.h
+++ b/libs/pbd/pbd/pathexpand.h
@@ -22,6 +22,7 @@
#include <string>
namespace PBD {
+ std::string canonical_path (const std::string& path);
std::string path_expand (std::string path);
std::string search_path_expand (std::string path);
}