- subst(os::slashify_path(s),'/','!'));
-
- // Rename is the wrong way of making a backup,
- // this is the correct way.
- /* truss cp fil fil2:
- lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
- stat("LyXVC.lyx", 0xEFFFF688) = 0
- open("LyXVC.lyx", O_RDONLY) = 3
- open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
- fstat(4, 0xEFFFF508) = 0
- fstat(3, 0xEFFFF508) = 0
- read(3, " # T h i s f i l e w".., 8192) = 5579
- write(4, " # T h i s f i l e w".., 5579) = 5579
- read(3, 0xEFFFD4A0, 8192) = 0
- close(4) = 0
- close(3) = 0
- chmod("LyXVC3.lyx", 0100644) = 0
- lseek(0, 0, SEEK_CUR) = 46440
- _exit(0)
- */
-
- // Should probably have some more error checking here.
- // Doing it this way, also makes the inodes stay the same.
- // This is still not a very good solution, in particular we
- // might loose the owner of the backup.
- FileInfo finfo(fileName());
- if (finfo.exist()) {
- mode_t fmode = finfo.getMode();
- struct utimbuf times = {
- finfo.getAccessTime(),
- finfo.getModificationTime() };
-
- ifstream ifs(fileName().c_str());
- ofstream ofs(s.c_str(), ios::out|ios::trunc);
- if (ifs && ofs) {
- ofs << ifs.rdbuf();
- ifs.close();
- ofs.close();
- ::chmod(s.c_str(), fmode);
-
- if (::utime(s.c_str(), ×)) {
- lyxerr << "utime error." << endl;
- }
- } else {
- lyxerr << "LyX was not able to make "
- "backup copy. Beware." << endl;
- }
+ subst(os::internal_path(s),'/','!'));
+
+ // It might very well be that this variant is just
+ // good enough. (Lgb)
+ // But to use this we need fs::copy_file to actually do a copy,
+ // even when the target file exists. (Lgb)
+ if (fs::exists(fileName()) && fs::is_writable(fs::path(fileName()).branch_path())) {
+ //try {
+ fs::copy_file(fileName(), s, false);
+ //}
+ //catch (fs::filesystem_error const & fe) {
+ //lyxerr << "LyX was not able to make backup copy. Beware.\n"
+ // << fe.what() << endl;
+ //}