From c81f5add994f22b47b93245ce3e32648102542f3 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 14 Jan 2008 09:04:14 +0000 Subject: [PATCH] * AutoSaveBuffer::generateChild(): return early. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22546 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 6e178c35c2..7ccf355a8e 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2271,33 +2271,35 @@ int AutoSaveBuffer::generateChild() pid_t const pid = fork(); // If you want to debug the autosave // you should set pid to -1, and comment out the fork. - if (pid == 0 || pid == -1) { - // pid = -1 signifies that lyx was unable - // to fork. But we will do the save - // anyway. - bool failed = false; - - FileName const tmp_ret = FileName::tempName("lyxauto"); - if (!tmp_ret.empty()) { - buffer_.writeFile(tmp_ret); - // assume successful write of tmp_ret - if (!tmp_ret.moveTo(fname_)) - failed = true; - } else + if (pid != 0 && pid != -1) + return pid; + + // pid = -1 signifies that lyx was unable + // to fork. But we will do the save + // anyway. + bool failed = false; + FileName const tmp_ret = FileName::tempName("lyxauto"); + if (!tmp_ret.empty()) { + buffer_.writeFile(tmp_ret); + // assume successful write of tmp_ret + if (!tmp_ret.moveTo(fname_)) failed = true; - - if (failed) { - // failed to write/rename tmp_ret so try writing direct - if (!buffer_.writeFile(fname_)) { - // It is dangerous to do this in the child, - // but safe in the parent, so... - if (pid == -1) // emit message signal. - buffer_.message(_("Autosave failed!")); - } + } else + failed = true; + + if (failed) { + // failed to write/rename tmp_ret so try writing direct + if (!buffer_.writeFile(fname_)) { + // It is dangerous to do this in the child, + // but safe in the parent, so... + if (pid == -1) // emit message signal. + buffer_.message(_("Autosave failed!")); } - if (pid == 0) // we are the child so... - _exit(0); } + + if (pid == 0) // we are the child so... + _exit(0); + return pid; } -- 2.39.5