- minibuffer->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;
- FilePtr fin(buf->fileName(), FilePtr::read);
- FilePtr fout(s, FilePtr::truncate);
- if (fin() && fout()) {
- char * cbuf = new char[blksize+1];
- size_t c_read = 0;
- size_t c_write = 0;
- do {
- c_read = fread(cbuf, 1, blksize, fin);
- if (c_read != 0)
- c_write =
- fwrite(cbuf, 1, c_read, fout);
- } while (c_read);
- fin.close();
- fout.close();
- chmod(s.c_str(), fmode);
-
- if (utime(s.c_str(), times)) {
- lyxerr << "utime error." << endl;
- }
- delete [] cbuf;
- } else {
- lyxerr << "LyX was not able to make backupcopy. Beware." << endl;
- }
- delete[] times;
- }
- }
-
- if (buf->writeFile(buf->fileName(), false)) {
- buf->markLyxClean();
-
- minibuffer->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());