Use functions in pbd/filesystem.h in Session::save_state for portability
Add ARDOUR::temp_suffix to ardour/filename_extensions.h/cc git-svn-id: svn://localhost/ardour2/trunk@2375 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
b49e50afac
commit
653a552da5
@ -9,6 +9,7 @@ extern const char* const statefile_suffix;
|
|||||||
extern const char* const pending_suffix;
|
extern const char* const pending_suffix;
|
||||||
extern const char* const peakfile_suffix;
|
extern const char* const peakfile_suffix;
|
||||||
extern const char* const backup_suffix;
|
extern const char* const backup_suffix;
|
||||||
|
extern const char* const temp_suffix;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,5 +9,6 @@ const char* const statefile_suffix = X_(".ardour");
|
|||||||
const char* const pending_suffix = X_(".pending");
|
const char* const pending_suffix = X_(".pending");
|
||||||
const char* const peakfile_suffix = X_(".peak");
|
const char* const peakfile_suffix = X_(".peak");
|
||||||
const char* const backup_suffix = X_(".bak");
|
const char* const backup_suffix = X_(".bak");
|
||||||
|
const char* const temp_suffix = X_(".tmp");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -558,8 +558,8 @@ int
|
|||||||
Session::save_state (string snapshot_name, bool pending)
|
Session::save_state (string snapshot_name, bool pending)
|
||||||
{
|
{
|
||||||
XMLTree tree;
|
XMLTree tree;
|
||||||
string xml_path;
|
sys::path xml_path(_session_dir->root_path());
|
||||||
string bak_path;
|
sys::path bak_path(xml_path);
|
||||||
|
|
||||||
if (_state_of_the_state & CannotSave) {
|
if (_state_of_the_state & CannotSave) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -585,45 +585,39 @@ Session::save_state (string snapshot_name, bool pending)
|
|||||||
if (!pending) {
|
if (!pending) {
|
||||||
|
|
||||||
/* proper save: use statefile_suffix (.ardour in English) */
|
/* proper save: use statefile_suffix (.ardour in English) */
|
||||||
xml_path = _path;
|
|
||||||
xml_path += snapshot_name;
|
xml_path /= snapshot_name + statefile_suffix;
|
||||||
xml_path += statefile_suffix;
|
|
||||||
|
|
||||||
/* make a backup copy of the old file */
|
/* make a backup copy of the old file */
|
||||||
bak_path = xml_path;
|
bak_path /= snapshot_name + statefile_suffix + backup_suffix;
|
||||||
bak_path += ".bak";
|
|
||||||
|
|
||||||
if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
|
if (sys::exists (xml_path)) {
|
||||||
copy_file (xml_path, bak_path);
|
copy_file (xml_path.to_string(), bak_path.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* pending save: use pending_suffix (.pending in English) */
|
/* pending save: use pending_suffix (.pending in English) */
|
||||||
xml_path = _path;
|
xml_path /= snapshot_name + pending_suffix;
|
||||||
xml_path += snapshot_name;
|
|
||||||
xml_path += pending_suffix;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string tmp_path;
|
sys::path tmp_path(_session_dir->root_path());
|
||||||
|
|
||||||
tmp_path = _path;
|
tmp_path /= snapshot_name + temp_suffix;
|
||||||
tmp_path += snapshot_name;
|
|
||||||
tmp_path += ".tmp";
|
|
||||||
|
|
||||||
// cerr << "actually writing state to " << xml_path << endl;
|
// cerr << "actually writing state to " << xml_path.to_string() << endl;
|
||||||
|
|
||||||
if (!tree.write (tmp_path)) {
|
if (!tree.write (tmp_path.to_string())) {
|
||||||
error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg;
|
error << string_compose (_("state could not be saved to %1"), tmp_path.to_string()) << endmsg;
|
||||||
unlink (tmp_path.c_str());
|
sys::remove (tmp_path);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (rename (tmp_path.c_str(), xml_path.c_str()) != 0) {
|
if (rename (tmp_path.to_string().c_str(), xml_path.to_string().c_str()) != 0) {
|
||||||
error << string_compose (_("could not rename temporary session file %1 to %2"), tmp_path, xml_path) << endmsg;
|
error << string_compose (_("could not rename temporary session file %1 to %2"),
|
||||||
unlink (tmp_path.c_str());
|
tmp_path.to_string(), xml_path.to_string()) << endmsg;
|
||||||
|
sys::remove (tmp_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user