summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2012-06-23 05:07:42 +0000
committerTim Mayberry <mojofunk@gmail.com>2012-06-23 05:07:42 +0000
commit2f507c8a764d4647385c16e7a12be276422b2a7a (patch)
treec46b4ca2a6b56ef00a08d67fcd034b3f8b514924 /libs/pbd
parent4363a6920f0340be4416d79b290f0696eae6c667 (diff)
Use giomm in PBD::sys::copy_file and change function signature
now returns bool to indicate successful copy rather than throw and takes strings as args git-svn-id: svn://localhost/ardour2/branches/3.0@12850 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/filesystem.cc39
-rw-r--r--libs/pbd/pbd/filesystem.h7
2 files changed, 23 insertions, 23 deletions
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