The attached addresses http://bugzilla.lyx.org/show_bug.cgi?id=2199,
crash on inclusion of files on which lyx2lyx chokes. The problem seems
to have been with the logic generally. It seems to have been assumed
that a file that could not be loaded wasn't a LyX file at all, but the
buffer for it was left open.

There's another logic issue I've fixed along the way. I'd appreciate if
someone would look at this, too. It's the return statement I've put
after "if (runparams.inComment || runparams.dryrun)". It doesn't seem to
me that we should be doing all the other stuff in this case, but I could
be wrong.

Seeking two OKs to commit.

Richard

-- 
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: InsetInclude.cpp
===================================================================
--- InsetInclude.cpp	(revision 18481)
+++ InsetInclude.cpp	(working copy)
@@ -389,12 +389,14 @@
 		if (!fs::exists(included_file.toFilesystemEncoding()))
 			return false;
 		buf = theBufferList().newBuffer(included_file.absFilename());
-		if (!loadLyXFile(buf, included_file))
+		if (!loadLyXFile(buf, included_file)) {
+			//close the buffer we just opened
+			theBufferList().close(buf, false);
 			return false;
+		}
 	}
-	if (buf)
-		buf->setParentName(parentFilename(buffer));
-	return buf != 0;
+	buf->setParentName(parentFilename(buffer));
+	return true;
 }
 
 
@@ -416,7 +418,9 @@
 	//FIXME RECURSIVE INCLUDE
 	//This isn't sufficient, as the inclusion could be downstream.
 	//But it'll have to do for now.
-	if (!isListings(params_) && buffer.fileName() == included_file.toFilesystemEncoding()) {
+	if (!isListings(params_) && 
+		buffer.fileName() == included_file.toFilesystemEncoding()) 
+	{
 		Alert::error(_("Recursive input"), 
 		               bformat(_("Attempted to include file %1$s in itself! "
 		               "Ignoring inclusion."), from_utf8(incfile)));
@@ -435,8 +439,9 @@
 
 	// write it to a file (so far the complete file)
 	string const exportfile = changeExtension(incfile, ".tex");
-	string const mangled = DocFileName(changeExtension(included_file.absFilename(),
-							".tex")).mangledFilename();
+	string const mangled = 
+		DocFileName(changeExtension(included_file.absFilename(),".tex")).
+			mangledFilename();
 	FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
 
 	if (!runparams.nice)
@@ -447,8 +452,11 @@
 
 	if (runparams.inComment || runparams.dryrun)
 		// Don't try to load or copy the file
-		;
-	else if (loadIfNeeded(buffer, params_)) {
+		return true;
+	else if (isLyXFilename(included_file.absFilename())) {
+		if (!loadIfNeeded(buffer, params_))
+			return false;
+			
 		Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
 
 		if (tmp->params().textclass != m_buffer->params().textclass) {

Reply via email to