diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2012-06-23 05:07:49 +0000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2012-06-23 05:07:49 +0000 |
commit | a22dd8c20a656a36d93e3e31ee3c04ca7e9b7278 (patch) | |
tree | 7fbf1b3717c478815bee4ad782ccc4b16fdb1218 /libs/pbd/file_utils.cc | |
parent | 4cda435203600e7e422525c6336baab483d6f009 (diff) |
Move PBD::sys::copy_file/s into pbd/file_utils.h and PBD:: namespace
Copy files no longer depends on PBD::sys::path so move it
git-svn-id: svn://localhost/ardour2/branches/3.0@12853 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/file_utils.cc')
-rw-r--r-- | libs/pbd/file_utils.cc | 46 |
1 files changed, 45 insertions, 1 deletions
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 |