- current_view->owner()->getMiniBuffer()->Set(_("Saving document"),
- MakeDisplayPath(buf->fileName()), "...");
-
- // We don't need autosaves in the immediate future. (Asger)
- buf->resetAutosaveTimers();
-
- // make a backup
- if (makeBackup) {
- string s = buf->fileName() + '~';
- // 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 proabaly have some more error checking here.
- // Should be cleaned up in 0.13, at least a bit.
- // 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(buf->fileName());
- if (finfo.exist()) {
- mode_t fmode = finfo.getMode();
- struct utimbuf * times = new struct utimbuf;
-
- times->actime = finfo.getAccessTime();
- times->modtime = finfo.getModificationTime();
- long blksize = finfo.getBlockSize();
- lyxerr.debug() << "BlockSize: " << blksize << endl;
- ifstream ifs(buf->fileName().c_str());
- ofstream ofs(s.c_str(), ios::out|ios::trunc);
- if (ifs && ofs) {
- char c = 0;
- while (ifs.get(c)) {
- ofs.put(c);
- };
- ifs.close();
- ofs.close();
- chmod(s.c_str(), fmode);
-
- if (utime(s.c_str(), times)) {
- lyxerr << "utime error." << endl;
- }
- } else {
- lyxerr << "LyX was not able to make "
- "backupcopy. Beware." << endl;
- }
- delete[] times;
- }
- }
-
- if (buf->writeFile(buf->fileName(), false)) {
- buf->markLyxClean();
-
- current_view->owner()->getMiniBuffer()->
- Set(_("Document saved as"),
- MakeDisplayPath(buf->fileName()));
-
- // now delete the autosavefile
- string a = OnlyPath(buf->fileName());
- a += '#';
- a += OnlyFilename(buf->fileName());
- a += '#';
- FileInfo fileinfo(a);
- if (fileinfo.exist()) {
- if (remove(a.c_str()) != 0) {
- WriteFSAlert(_("Could not delete "
- "auto-save file!"), a);
- }
- }
- } else {
- // Saving failed, so backup is not backup
- if (makeBackup) {
- string s = buf->fileName() + '~';
- rename(s.c_str(), buf->fileName().c_str());