summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2007-09-04 04:48:11 +0000
committerTim Mayberry <mojofunk@gmail.com>2007-09-04 04:48:11 +0000
commit653a552da503f3d9e250958998868c2021bef823 (patch)
treef44f5bacc892cd3ca2ac2741518b6b0d1faeb86d /libs/ardour
parentb49e50afacdfba7bf799c290b783daf3a0c5cfef (diff)
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
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/filename_extensions.h1
-rw-r--r--libs/ardour/filename_extensions.cc1
-rw-r--r--libs/ardour/session_state.cc42
3 files changed, 20 insertions, 24 deletions
diff --git a/libs/ardour/ardour/filename_extensions.h b/libs/ardour/ardour/filename_extensions.h
index 06ffe4b0e1..abd7871009 100644
--- a/libs/ardour/ardour/filename_extensions.h
+++ b/libs/ardour/ardour/filename_extensions.h
@@ -9,6 +9,7 @@ extern const char* const statefile_suffix;
extern const char* const pending_suffix;
extern const char* const peakfile_suffix;
extern const char* const backup_suffix;
+extern const char* const temp_suffix;
}
diff --git a/libs/ardour/filename_extensions.cc b/libs/ardour/filename_extensions.cc
index 9361c7a3da..ebf8f87443 100644
--- a/libs/ardour/filename_extensions.cc
+++ b/libs/ardour/filename_extensions.cc
@@ -9,5 +9,6 @@ const char* const statefile_suffix = X_(".ardour");
const char* const pending_suffix = X_(".pending");
const char* const peakfile_suffix = X_(".peak");
const char* const backup_suffix = X_(".bak");
+const char* const temp_suffix = X_(".tmp");
}
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 99cf4ba4a3..83609d351d 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -558,8 +558,8 @@ int
Session::save_state (string snapshot_name, bool pending)
{
XMLTree tree;
- string xml_path;
- string bak_path;
+ sys::path xml_path(_session_dir->root_path());
+ sys::path bak_path(xml_path);
if (_state_of_the_state & CannotSave) {
return 1;
@@ -585,45 +585,39 @@ Session::save_state (string snapshot_name, bool pending)
if (!pending) {
/* proper save: use statefile_suffix (.ardour in English) */
- xml_path = _path;
- xml_path += snapshot_name;
- xml_path += statefile_suffix;
+
+ xml_path /= snapshot_name + statefile_suffix;
/* make a backup copy of the old file */
- bak_path = xml_path;
- bak_path += ".bak";
+ bak_path /= snapshot_name + statefile_suffix + backup_suffix;
- if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
- copy_file (xml_path, bak_path);
+ if (sys::exists (xml_path)) {
+ copy_file (xml_path.to_string(), bak_path.to_string());
}
} else {
/* pending save: use pending_suffix (.pending in English) */
- xml_path = _path;
- xml_path += snapshot_name;
- xml_path += pending_suffix;
-
+ xml_path /= snapshot_name + pending_suffix;
}
- string tmp_path;
+ sys::path tmp_path(_session_dir->root_path());
- tmp_path = _path;
- tmp_path += snapshot_name;
- tmp_path += ".tmp";
+ tmp_path /= snapshot_name + temp_suffix;
- // cerr << "actually writing state to " << xml_path << endl;
+ // cerr << "actually writing state to " << xml_path.to_string() << endl;
- if (!tree.write (tmp_path)) {
- error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg;
- unlink (tmp_path.c_str());
+ if (!tree.write (tmp_path.to_string())) {
+ error << string_compose (_("state could not be saved to %1"), tmp_path.to_string()) << endmsg;
+ sys::remove (tmp_path);
return -1;
} else {
- if (rename (tmp_path.c_str(), xml_path.c_str()) != 0) {
- error << string_compose (_("could not rename temporary session file %1 to %2"), tmp_path, xml_path) << endmsg;
- unlink (tmp_path.c_str());
+ 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.to_string(), xml_path.to_string()) << endmsg;
+ sys::remove (tmp_path);
return -1;
}
}