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
This commit is contained in:
Tim Mayberry 2012-06-23 05:07:49 +00:00
parent 4cda435203
commit a22dd8c20a
7 changed files with 67 additions and 62 deletions

View 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();
}
}

View 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;
}

View 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

View file

@ -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

View 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)
{

View 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

View 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.