Use a different naming scheme, per Enrico's suggestion.

(cherry picked from commit 533a05e0b8)
This commit is contained in:
Richard Heck 2014-06-04 12:46:42 -04:00
parent b9db0c1321
commit fff454fa4b

View File

@ -1285,10 +1285,13 @@ bool Buffer::save() const
// proper location once that has been done successfully. that // proper location once that has been done successfully. that
// way we preserve the original file if something goes wrong. // way we preserve the original file if something goes wrong.
string const savepath = fileName().onlyPath().absFileName(); string const savepath = fileName().onlyPath().absFileName();
string savename = "tmp-" + fileName().onlyFileName(); int fnum = 1;
string const fname = fileName().onlyFileName();
string savename = "tmp-" + convert<string>(fnum) + "-" + fname;
FileName savefile(addName(savepath, savename)); FileName savefile(addName(savepath, savename));
while (savefile.exists()) { while (savefile.exists()) {
if (savefile.absFileName().size() > 1024) { // surely that is enough tries?
if (fnum > 100) {
Alert::error(_("Write failure"), Alert::error(_("Write failure"),
bformat(_("Cannot find temporary filename for:\n %1$s.\n" bformat(_("Cannot find temporary filename for:\n %1$s.\n"
"Even %2$s exists!"), "Even %2$s exists!"),
@ -1296,7 +1299,8 @@ bool Buffer::save() const
from_utf8(savefile.absFileName()))); from_utf8(savefile.absFileName())));
return false; return false;
} }
savename = "tmp-" + savename; fnum += 1;
savename = "tmp-" + convert<string>(fnum) + "-" + fname;
savefile.set(addName(savepath, savename)); savefile.set(addName(savepath, savename));
} }