copy older versions of the session file, fix up ardev to work again using %VERSION%
[ardour.git] / libs / pbd / copyfile.cc
1 #include <fstream>
2 #include <unistd.h>
3
4 #include <pbd/copyfile.h>
5 #include <pbd/error.h>
6 #include <pbd/compose.h>
7
8 #include "i18n.h"
9
10 using namespace PBD;
11 using namespace std;
12
13 int
14 PBD::copy_file (Glib::ustring from, Glib::ustring to)
15 {
16         ifstream in (from.c_str());
17         ofstream out (to.c_str());
18         
19         if (!in) {
20                 error << string_compose (_("Could not open %1 for copy"), from) << endmsg;
21                 return -1;
22         }
23         
24         if (!out) {
25                 error << string_compose (_("Could not open %1 as copy"), to) << endmsg;
26                 return -1;
27         }
28         
29         out << in.rdbuf();
30         
31         if (!in || !out) {
32                 error << string_compose (_("Could not copy existing file %1 to %2"), from, to) << endmsg;
33                 unlink (to.c_str());
34                 return -1;
35         }
36         
37         return 0;
38 }