mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-02 05:55:38 +00:00
Revert "Use a different naming scheme, per Enrico's suggestion."
This reverts commitfff454fa4b
. Revert "Per a suggestion of JMarc's, first write the saved file to a" This reverts commit094129f804
.
This commit is contained in:
parent
2c50241da9
commit
a72e68dd09
@ -1276,42 +1276,12 @@ bool Buffer::save() const
|
|||||||
// We don't need autosaves in the immediate future. (Asger)
|
// We don't need autosaves in the immediate future. (Asger)
|
||||||
resetAutosaveTimers();
|
resetAutosaveTimers();
|
||||||
|
|
||||||
// if the file does not yet exist, none of the backup activity
|
FileName backupName;
|
||||||
// that follows is necessary
|
bool madeBackup = false;
|
||||||
if (!fileName().exists())
|
|
||||||
return writeFile(fileName());
|
|
||||||
|
|
||||||
// we first write the file to a new name, then move it to its
|
// make a backup if the file already exists
|
||||||
// proper location once that has been done successfully. that
|
if (lyxrc.make_backup && fileName().exists()) {
|
||||||
// way we preserve the original file if something goes wrong.
|
backupName = FileName(absFileName() + '~');
|
||||||
string const savepath = fileName().onlyPath().absFileName();
|
|
||||||
int fnum = 1;
|
|
||||||
string const fname = fileName().onlyFileName();
|
|
||||||
string savename = "tmp-" + convert<string>(fnum) + "-" + fname;
|
|
||||||
FileName savefile(addName(savepath, savename));
|
|
||||||
while (savefile.exists()) {
|
|
||||||
// surely that is enough tries?
|
|
||||||
if (fnum > 100) {
|
|
||||||
Alert::error(_("Write failure"),
|
|
||||||
bformat(_("Cannot find temporary filename for:\n %1$s.\n"
|
|
||||||
"Even %2$s exists!"),
|
|
||||||
from_utf8(fileName().absFileName()),
|
|
||||||
from_utf8(savefile.absFileName())));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fnum += 1;
|
|
||||||
savename = "tmp-" + convert<string>(fnum) + "-" + fname;
|
|
||||||
savefile.set(addName(savepath, savename));
|
|
||||||
}
|
|
||||||
|
|
||||||
LYXERR(Debug::FILES, "Saving to " << savefile.absFileName());
|
|
||||||
if (!writeFile(savefile))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// we will set this to false if we fail
|
|
||||||
bool made_backup = true;
|
|
||||||
if (lyxrc.make_backup) {
|
|
||||||
FileName backupName(absFileName() + '~');
|
|
||||||
if (!lyxrc.backupdir_path.empty()) {
|
if (!lyxrc.backupdir_path.empty()) {
|
||||||
string const mangledName =
|
string const mangledName =
|
||||||
subst(subst(backupName.absFileName(), '/', '!'), ':', '!');
|
subst(subst(backupName.absFileName(), '/', '!'), ':', '!');
|
||||||
@ -1321,11 +1291,12 @@ bool Buffer::save() const
|
|||||||
|
|
||||||
// Except file is symlink do not copy because of #6587.
|
// Except file is symlink do not copy because of #6587.
|
||||||
// Hard links have bad luck.
|
// Hard links have bad luck.
|
||||||
made_backup = fileName().isSymLink() ?
|
if (fileName().isSymLink())
|
||||||
fileName().copyTo(backupName):
|
madeBackup = fileName().copyTo(backupName);
|
||||||
fileName().moveTo(backupName);
|
else
|
||||||
|
madeBackup = fileName().moveTo(backupName);
|
||||||
|
|
||||||
if (!made_backup) {
|
if (!madeBackup) {
|
||||||
Alert::error(_("Backup failure"),
|
Alert::error(_("Backup failure"),
|
||||||
bformat(_("Cannot create backup file %1$s.\n"
|
bformat(_("Cannot create backup file %1$s.\n"
|
||||||
"Please check whether the directory exists and is writable."),
|
"Please check whether the directory exists and is writable."),
|
||||||
@ -1333,18 +1304,16 @@ bool Buffer::save() const
|
|||||||
//LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
|
//LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (made_backup && savefile.moveTo(fileName())) {
|
if (writeFile(d->filename)) {
|
||||||
markClean();
|
markClean();
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
// Saving failed, so backup is not backup
|
||||||
|
if (madeBackup)
|
||||||
|
backupName.moveTo(d->filename);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// else
|
|
||||||
Alert::error(_("Write failure"),
|
|
||||||
bformat(_("Cannot move saved file to:\n %1$s.\n"
|
|
||||||
"But the file has successfully been saved as:\n %2$s."),
|
|
||||||
from_utf8(fileName().absFileName()),
|
|
||||||
from_utf8(savefile.absFileName())));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@ What's new
|
|||||||
|
|
||||||
* DOCUMENT INPUT/OUTPUT
|
* DOCUMENT INPUT/OUTPUT
|
||||||
|
|
||||||
- When saving a file, LyX now writes the saved file first to a temporary
|
|
||||||
filename (tmp-oldfile.lyx) and only deletes the original file once the
|
|
||||||
new file has successfully been written.
|
|
||||||
|
|
||||||
- We now flush the output stream more frequently, as a temporary measure
|
- We now flush the output stream more frequently, as a temporary measure
|
||||||
to help us gather information about the crash mentioned above.
|
to help us gather information about the crash mentioned above.
|
||||||
|
Loading…
Reference in New Issue
Block a user