diff options
-rw-r--r-- | libs/ardour/export_graph_builder.cc | 4 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 7 | ||||
-rw-r--r-- | libs/ardour/session_state_utils.cc | 2 | ||||
-rw-r--r-- | libs/pbd/file_utils.cc | 46 | ||||
-rw-r--r-- | libs/pbd/filesystem.cc | 40 | ||||
-rw-r--r-- | libs/pbd/pbd/file_utils.h | 16 | ||||
-rw-r--r-- | libs/pbd/pbd/filesystem.h | 14 |
7 files changed, 67 insertions, 62 deletions
diff --git a/libs/ardour/export_graph_builder.cc b/libs/ardour/export_graph_builder.cc index fbb5d0f98a..5061bcecfd 100644 --- a/libs/ardour/export_graph_builder.cc +++ b/libs/ardour/export_graph_builder.cc @@ -18,7 +18,7 @@ #include "ardour/export_timespan.h" #include "ardour/sndfile_helpers.h" -#include "pbd/filesystem.h" +#include "pbd/file_utils.h" #include "pbd/cpus.h" using namespace AudioGrapher; @@ -216,7 +216,7 @@ ExportGraphBuilder::Encoder::copy_files (std::string orig_path) { while (filenames.size()) { ExportFilenamePtr & filename = filenames.front(); - PBD::sys::copy_file (orig_path, filename->get_path (config.format).c_str()); + PBD::copy_file (orig_path, filename->get_path (config.format).c_str()); filenames.pop_front(); } } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 7107ebee50..58a3d1075b 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -69,6 +69,7 @@ #include "pbd/enumwriter.h" #include "pbd/error.h" #include "pbd/filesystem.h" +#include "pbd/file_utils.h" #include "pbd/pathscanner.h" #include "pbd/pthread_utils.h" #include "pbd/search_path.h" @@ -540,7 +541,7 @@ Session::create (const string& session_template, BusProfile* bus_profile) /* Copy plugin state files from template to new session */ std::string template_plugins = Glib::build_filename (session_template, X_("plugins")); - sys::copy_files (template_plugins, plugins_dir ()); + copy_files (template_plugins, plugins_dir ()); return 0; @@ -943,7 +944,7 @@ Session::load_state (string snapshot_name) xmlpath.to_string(), backup_path.to_string(), PROGRAM_NAME) << endmsg; - if (!sys::copy_file (xmlpath.to_string(), backup_path.to_string())) {; + if (!copy_file (xmlpath.to_string(), backup_path.to_string())) {; return -1; } } @@ -2069,7 +2070,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.to_string()); + copy_files (plugins_dir(), template_plugin_state_path.to_string()); return 0; } diff --git a/libs/ardour/session_state_utils.cc b/libs/ardour/session_state_utils.cc index a7be0583f9..94cbe9f232 100644 --- a/libs/ardour/session_state_utils.cc +++ b/libs/ardour/session_state_utils.cc @@ -41,7 +41,7 @@ namespace ARDOUR { bool create_backup_file (const std::string & file_path) { - return sys::copy_file (file_path, file_path + backup_suffix); + return copy_file (file_path, file_path + backup_suffix); } void diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 162997cbbd..956b7002cb 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -23,10 +23,14 @@ #include <glibmm/miscutils.h> #include <glibmm/pattern.h> +#include <giomm/file.h> + #include "pbd/compose.h" #include "pbd/file_utils.h" - #include "pbd/error.h" +#include "pbd/pathscanner.h" + +#include "i18n.h" using namespace std; @@ -125,4 +129,44 @@ find_file_in_search_path(const SearchPath& search_path, return true; } +bool +copy_file(const std::string & from_path, const std::string & to_path) +{ + 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); + } + 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 +bool accept_all_files (string const &, void *) +{ + return true; +} + +void +copy_files(const std::string & from_path, const std::string & to_dir) +{ + PathScanner scanner; + vector<string*>* files = scanner (from_path, accept_all_files, 0, true, false); + for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) { + std::string from = Glib::build_filename (from_path, **i); + std::string to = Glib::build_filename (to_dir, **i); + copy_file (from, to); + } +} + } // namespace PBD diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc index cd88bac6a9..c1a8111b48 100644 --- a/libs/pbd/filesystem.cc +++ b/libs/pbd/filesystem.cc @@ -184,47 +184,7 @@ rename (const path & from_path, const path & to_path) throw filesystem_error(g_strerror(errno), errno); } } - -bool -copy_file(const std::string & from_path, const std::string & to_path) -{ - 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); - } - 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 -bool accept_all_files (string const &, void *) -{ - return true; -} -void -copy_files(const std::string & from_path, const std::string & to_dir) -{ - PathScanner scanner; - vector<string*>* files = scanner (from_path, accept_all_files, 0, true, false); - for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) { - std::string from = Glib::build_filename (from_path, **i); - std::string to = Glib::build_filename (to_dir, **i); - copy_file (from, to); - } -} - string basename (const path & p) { diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h index b303936fab..8f5b6d1e25 100644 --- a/libs/pbd/pbd/file_utils.h +++ b/libs/pbd/pbd/file_utils.h @@ -90,7 +90,21 @@ bool find_file_in_search_path (const SearchPath& search_path, const std::string& filename, std::string& result); - + +/** + * Attempt to copy the contents of the file from_path to a new file + * at path to_path. + * + * @return true if file was successfully copied + */ +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 std::string & from_path, const std::string & to_dir); + } // namespace PBD #endif diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h index c956c8beb1..aa9f9ef502 100644 --- a/libs/pbd/pbd/filesystem.h +++ b/libs/pbd/pbd/filesystem.h @@ -170,20 +170,6 @@ bool remove(const path & p); 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. - * - * @return true if file was successfully copied - */ -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 std::string & from_path, const std::string & to_dir); - -/** * @return The substring of the filename component of the path, starting * at the beginning of the filename up to but not including the last dot. * |