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
This commit is contained in:
parent
4363a6920f
commit
2f507c8a76
@ -45,6 +45,8 @@
|
|||||||
#include <xmmintrin.h>
|
#include <xmmintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <giomm.h>
|
||||||
|
|
||||||
#include <glibmm/fileutils.h>
|
#include <glibmm/fileutils.h>
|
||||||
#include <glibmm/miscutils.h>
|
#include <glibmm/miscutils.h>
|
||||||
|
|
||||||
@ -216,6 +218,9 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization)
|
|||||||
Glib::thread_init();
|
Glib::thread_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this really should be in PBD::init..if there was one
|
||||||
|
Gio::init ();
|
||||||
|
|
||||||
(void) bindtextdomain(PACKAGE, LOCALEDIR);
|
(void) bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
|
|
||||||
PBD::ID::init ();
|
PBD::ID::init ();
|
||||||
|
@ -539,8 +539,7 @@ Session::create (const string& session_template, BusProfile* bus_profile)
|
|||||||
_is_new = false;
|
_is_new = false;
|
||||||
|
|
||||||
/* Copy plugin state files from template to new session */
|
/* Copy plugin state files from template to new session */
|
||||||
sys::path template_plugins = session_template;
|
std::string template_plugins = Glib::build_filename (session_template, X_("plugins"));
|
||||||
template_plugins /= X_("plugins");
|
|
||||||
sys::copy_files (template_plugins, plugins_dir ());
|
sys::copy_files (template_plugins, plugins_dir ());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -944,14 +943,7 @@ Session::load_state (string snapshot_name)
|
|||||||
xmlpath.to_string(), backup_path.to_string(), PROGRAM_NAME)
|
xmlpath.to_string(), backup_path.to_string(), PROGRAM_NAME)
|
||||||
<< endmsg;
|
<< endmsg;
|
||||||
|
|
||||||
try {
|
if (!sys::copy_file (xmlpath.to_string(), backup_path.to_string())) {;
|
||||||
sys::copy_file (xmlpath, backup_path);
|
|
||||||
|
|
||||||
} catch (sys::filesystem_error& ex) {
|
|
||||||
|
|
||||||
error << string_compose (_("Unable to make backup of state file %1 (%2)"),
|
|
||||||
xmlpath.to_string(), ex.what())
|
|
||||||
<< endmsg;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2077,7 +2069,7 @@ Session::save_template (string template_name)
|
|||||||
sys::path template_plugin_state_path = template_dir_path;
|
sys::path template_plugin_state_path = template_dir_path;
|
||||||
template_plugin_state_path /= X_("plugins");
|
template_plugin_state_path /= X_("plugins");
|
||||||
sys::create_directories (template_plugin_state_path);
|
sys::create_directories (template_plugin_state_path);
|
||||||
sys::copy_files (plugins_dir(), template_plugin_state_path);
|
sys::copy_files (plugins_dir(), template_plugin_state_path.to_string());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -185,25 +185,26 @@ rename (const path & from_path, const path & to_path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX character encoding.
|
bool
|
||||||
void
|
copy_file(const std::string & from_path, const std::string & to_path)
|
||||||
copy_file(const path & from_path, const path & to_path)
|
|
||||||
{
|
{
|
||||||
std::ifstream in(from_path.to_string().c_str());
|
if (!Glib::file_test (from_path, Glib::FILE_TEST_EXISTS)) return false;
|
||||||
std::ofstream out(to_path.to_string().c_str());
|
|
||||||
|
Glib::RefPtr<Gio::File> from_file = Gio::File::create_for_path(from_path);
|
||||||
if (!in || !out) {
|
Glib::RefPtr<Gio::File> to_file = Gio::File::create_for_path(to_path);
|
||||||
throw filesystem_error(string_compose(_("Could not open files %1 and %2 for copying"),
|
|
||||||
from_path.to_string(), to_path.to_string()));
|
try
|
||||||
|
{
|
||||||
|
from_file->copy (to_file);
|
||||||
}
|
}
|
||||||
|
catch(const Glib::Exception& ex)
|
||||||
out << in.rdbuf();
|
{
|
||||||
|
error << string_compose (_("Unable to Copy file %1 to %2 (%3)"),
|
||||||
if (!in || !out) {
|
from_path, to_path, ex.what())
|
||||||
remove (to_path);
|
<< endmsg;
|
||||||
throw filesystem_error(string_compose(_("Could not copy existing file %1 to %2"),
|
return false;
|
||||||
from_path.to_string(), to_path.to_string()));
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -213,17 +214,17 @@ bool accept_all_files (string const &, void *)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
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) {
|
for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) {
|
||||||
sys::path from = from_path;
|
sys::path from = from_path;
|
||||||
from /= **i;
|
from /= **i;
|
||||||
sys::path to = to_dir;
|
sys::path to = to_dir;
|
||||||
to /= **i;
|
to /= **i;
|
||||||
|
|
||||||
copy_file (from, to);
|
copy_file (from.to_string(), to.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* Attempt to copy the contents of the file from_path to a new file
|
||||||
* at path to_path.
|
* at path to_path.
|
||||||
*
|
*
|
||||||
* @throw filesystem_error if from_path.empty() || to_path.empty() ||
|
* @return true if file was successfully copied
|
||||||
* !exists(from_path) || !is_regular(from_path) || exists(to_path)
|
|
||||||
*/
|
*/
|
||||||
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.
|
* Attempt to copy all regular files from from_path to a new directory.
|
||||||
* This method does not recurse.
|
* 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
|
* @return The substring of the filename component of the path, starting
|
||||||
|
Loading…
Reference in New Issue
Block a user