Move PBD::sys::copy_file/s into pbd/file_utils.h and PBD:: namespace
authorTim Mayberry <mojofunk@gmail.com>
Sat, 23 Jun 2012 05:07:49 +0000 (05:07 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Sat, 23 Jun 2012 05:07:49 +0000 (05:07 +0000)
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

libs/ardour/export_graph_builder.cc
libs/ardour/session_state.cc
libs/ardour/session_state_utils.cc
libs/pbd/file_utils.cc
libs/pbd/filesystem.cc
libs/pbd/pbd/file_utils.h
libs/pbd/pbd/filesystem.h

index fbb5d0f98aa8140cdabf038f6d8d86dc29df2951..5061bcecfd290bb0c737e6dcf0df6a6c65cde32d 100644 (file)
@@ -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();
        }
 }
index 7107ebee50b2c20cce7f8b20ca73fde8fd2fd113..58a3d1075b9363d379bac7d0bc4f22837213c99e 100644 (file)
@@ -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;
 }
index a7be0583f9b0508e6b5d90a6962fe6f5d0ae288f..94cbe9f23210618a406387cff090b2fc05b8a0d7 100644 (file)
@@ -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
index 162997cbbd0e3242f7ebf54e1a13a3ee6cc8adb2..956b7002cbd12bcdd2234ca7d42f421e96431080 100644 (file)
 #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
index cd88bac6a9fdaa825a0ae312ba1b549537ca81ec..c1a8111b481b51859347d8bc7aa72fc9b4cdfe12 100644 (file)
@@ -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)
 {
index b303936fab8240e7559e56d16f279ab40fe12f1f..8f5b6d1e25bf15b4b74e21ae188c5bd4275380aa 100644 (file)
@@ -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
index c956c8beb1d10063db381b0f4709a31cef18f34a..aa9f9ef5021bebf5679316b940b2625f2f94e75e 100644 (file)
@@ -169,20 +169,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.