projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bump libdcp for another SMPTE subtitle correctness fix.
[dcpomatic.git]
/
src
/
lib
/
config.cc
diff --git
a/src/lib/config.cc
b/src/lib/config.cc
index 172890dcfbc34610a83a1d5b26ec64cdd0a6108f..9dd6f638e7c6e16ba29545f942dc1388ed887378 100644
(file)
--- a/
src/lib/config.cc
+++ b/
src/lib/config.cc
@@
-982,17
+982,15
@@
Config::write_config () const
try {
string const s = doc.write_to_string_formatted ();
try {
string const s = doc.write_to_string_formatted ();
- boost::filesystem::path
const cf = config_file (
);
- FILE* f = fopen_boost (
cf
, "w");
+ boost::filesystem::path
tmp (string(config_file().string()).append(".tmp")
);
+ FILE* f = fopen_boost (
tmp
, "w");
if (!f) {
if (!f) {
- throw FileError (_("Could not open file for writing"), cf);
- }
- size_t const w = fwrite (s.c_str(), 1, s.length(), f);
- if (w != s.length()) {
- fclose (f);
- throw FileError (_("Could not write whole file"), cf);
+ throw FileError (_("Could not open file for writing"), tmp);
}
}
+ checked_fwrite (s.c_str(), s.length(), f, tmp);
fclose (f);
fclose (f);
+ boost::filesystem::remove (config_file());
+ boost::filesystem::rename (tmp, config_file());
} catch (xmlpp::exception& e) {
string s = e.what ();
trim (s);
} catch (xmlpp::exception& e) {
string s = e.what ();
trim (s);
@@
-1012,7
+1010,9
@@
Config::write_cinemas () const
}
try {
}
try {
- doc.write_to_file_formatted (_cinemas_file.string ());
+ doc.write_to_file_formatted (_cinemas_file.string() + ".tmp");
+ boost::filesystem::remove (_cinemas_file);
+ boost::filesystem::rename (_cinemas_file.string() + ".tmp", _cinemas_file);
} catch (xmlpp::exception& e) {
string s = e.what ();
trim (s);
} catch (xmlpp::exception& e) {
string s = e.what ();
trim (s);
@@
-1237,10
+1237,16
@@
Config::config_file ()
}
/* See if there's a link */
}
/* See if there's a link */
- f.read_file (main);
- optional<string> link = f.optional_string_child("Link");
- if (link) {
- return *link;
+ try {
+ f.read_file (main);
+ optional<string> link = f.optional_string_child("Link");
+ if (link) {
+ return *link;
+ }
+ } catch (xmlpp::exception& e) {
+ /* There as a problem reading the main configuration file,
+ so there can't be a link.
+ */
}
return main;
}
return main;