summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/ardour/globals.cc5
-rw-r--r--libs/ardour/session_state.cc14
-rw-r--r--libs/pbd/filesystem.cc39
-rw-r--r--libs/pbd/pbd/filesystem.h7
4 files changed, 31 insertions, 34 deletions
diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc
index caad270195..b2fd8282fe 100644
--- a/libs/ardour/globals.cc
+++ b/libs/ardour/globals.cc
@@ -45,6 +45,8 @@
#include <xmmintrin.h>
#endif
+#include <giomm.h>
+
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
@@ -216,6 +218,9 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization)
Glib::thread_init();
}
+ // this really should be in PBD::init..if there was one
+ Gio::init ();
+
(void) bindtextdomain(PACKAGE, LOCALEDIR);
PBD::ID::init ();
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index c03be469cb..7107ebee50 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -539,8 +539,7 @@ Session::create (const string& session_template, BusProfile* bus_profile)
_is_new = false;
/* Copy plugin state files from template to new session */
- sys::path template_plugins = session_template;
- template_plugins /= X_("plugins");
+ std::string template_plugins = Glib::build_filename (session_template, X_("plugins"));
sys::copy_files (template_plugins, plugins_dir ());
return 0;
@@ -944,14 +943,7 @@ Session::load_state (string snapshot_name)
xmlpath.to_string(), backup_path.to_string(), PROGRAM_NAME)
<< endmsg;
- try {
- sys::copy_file (xmlpath, backup_path);
-
- } catch (sys::filesystem_error& ex) {
-
- error << string_compose (_("Unable to make backup of state file %1 (%2)"),
- xmlpath.to_string(), ex.what())
- << endmsg;
+ if (!sys::copy_file (xmlpath.to_string(), backup_path.to_string())) {;
return -1;
}
}
@@ -2077,7 +2069,7 @@ Session::save_template (string template_name)
sys::path template_plugin_state_path = template_dir_path;
template_plugin_state_path /= X_("plugins");
sys::create_directories (template_plugin_state_path);
- sys::copy_files (plugins_dir(), template_plugin_state_path);
+ sys::copy_files (plugins_dir(), template_plugin_state_path.to_string());
return 0;
}
diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc
index 344252f4ba..761c074d61 100644
--- a/libs/pbd/filesystem.cc
+++ b/libs/pbd/filesystem.cc
@@ -185,25 +185,26 @@ rename (const path & from_path, const path & to_path)
}
}
-// XXX character encoding.
-void
-copy_file(const path & from_path, const path & to_path)
+bool
+copy_file(const std::string & from_path, const std::string & to_path)
{
- std::ifstream in(from_path.to_string().c_str());
- std::ofstream out(to_path.to_string().c_str());
-
- if (!in || !out) {
- throw filesystem_error(string_compose(_("Could not open files %1 and %2 for copying"),
- from_path.to_string(), to_path.to_string()));
+ if (!Glib::file_test (from_path, Glib::FILE_TEST_EXISTS)) return false;
+
+ Glib::RefPtr<Gio::File> from_file = Gio::File::create_for_path(from_path);
+ Glib::RefPtr<Gio::File> to_file = Gio::File::create_for_path(to_path);
+
+ try
+ {
+ from_file->copy (to_file);
}
-
- out << in.rdbuf();
-
- if (!in || !out) {
- remove (to_path);
- throw filesystem_error(string_compose(_("Could not copy existing file %1 to %2"),
- from_path.to_string(), to_path.to_string()));
+ catch(const Glib::Exception& ex)
+ {
+ error << string_compose (_("Unable to Copy file %1 to %2 (%3)"),
+ from_path, to_path, ex.what())
+ << endmsg;
+ return false;
}
+ return true;
}
static
@@ -213,17 +214,17 @@ bool accept_all_files (string const &, void *)
}
void
-copy_files(const path & from_path, const path & to_dir)
+copy_files(const std::string & from_path, const std::string & to_dir)
{
PathScanner scanner;
- vector<string*>* files = scanner (from_path.to_string(), accept_all_files, 0, true, false);
+ vector<string*>* files = scanner (from_path, accept_all_files, 0, true, false);
for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) {
sys::path from = from_path;
from /= **i;
sys::path to = to_dir;
to /= **i;
- copy_file (from, to);
+ copy_file (from.to_string(), to.to_string());
}
}
diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h
index 1fb6fbc155..c956c8beb1 100644
--- a/libs/pbd/pbd/filesystem.h
+++ b/libs/pbd/pbd/filesystem.h
@@ -173,16 +173,15 @@ void rename (const path& from_path, const path& to_path);
* Attempt to copy the contents of the file from_path to a new file
* at path to_path.
*
- * @throw filesystem_error if from_path.empty() || to_path.empty() ||
- * !exists(from_path) || !is_regular(from_path) || exists(to_path)
+ * @return true if file was successfully copied
*/
-void copy_file(const path & from_path, const path & to_path);
+bool copy_file(const std::string & from_path, const std::string & to_path);
/**
* Attempt to copy all regular files from from_path to a new directory.
* This method does not recurse.
*/
-void copy_files(const path & from_path, const path & to_dir);
+void copy_files(const std::string & from_path, const std::string & to_dir);
/**
* @return The substring of the filename component of the path, starting