[PATCH] Bugs 643, 3047, and 3090

2007-05-18 Thread Richard Heck

The attached patch addresses these bugs, all of which have to do with
export, viewing, and the like---ultimately, with the conversion
routines. The patch introduces a new conversion flag, usetempdir, which
forces the converter to do all its work in a temporary directory created
under the lyx_tmpbuf directory. On export, this directory is copied to
the directory in which the LyX file is contained. So, if you open
/path/file.lyx and FileExportFormat, you will get a directory
/path/file.format.conversion/ in which all the files generated by the
converter will be found (e.g. the mess that htlatex generates ends up in
/path/file.html.conversion/). If you're just viewing, however, you get
$LYXTMPDIR/lyx_tmpbufN/format/, and of course that will get deleted when
LyX exits (gracefully).

As a result, the originaldir flag does not need to be used by any of our
converters, and it may be redundant, though there's no harm leaving it,
so far as I can see.

As you will note, doing this involved adding a new signature to the
Converters::convert() routine. I have not changed any of the other calls
to this: these are in Importer.cpp, insets/InsetGraphics.cpp, and
insets/ExternalSupport.cpp. At least some of these will need modifying
before the patch is applied, probably all of them, as I suppose
usetempdir could be set for importers and graphics converters and such.
There are a few other clean-up type things to be done still, too,
including fixing indentation, but I haven't done that yet as it would
make the diff hard to read.

Comments of course welcome. Will wait to commit for a bit, targeting for
RC1??

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: src/Converter.h
===
--- src/Converter.h	(revision 18380)
+++ src/Converter.h	(working copy)
@@ -59,6 +59,9 @@
 	bool original_dir;
 	/// This converter needs the .aux files
 	bool need_aux;
+	/// This converter should put its files in a separate temporary
+	/// directory
+	bool use_temp_dir;
 	/// If the converter put the result in a directory, then result_dir
 	/// is the name of the directory
 	std::string result_dir;
@@ -123,6 +126,14 @@
 	 support::FileName const  orig_from,
 	 std::string const  from_format, std::string const  to_format,
 	 ErrorList  errorList, int conversionflags = none);
+	/// used_tmp_dir is a flag that signals whether our output files were put into
+	/// a temporary directory. Note also that to_file will be changed so that it points 
+	/// at the converted file in this case.
+	bool convert(Buffer const * buffer,
+	 support::FileName const  from_file, support::FileName  to_file,
+	 support::FileName const  orig_from, bool  used_temp_dir,
+	 std::string const  from_format, std::string const  to_format,
+	 ErrorList  errorList, int conversionflags = none);
 	///
 	void update(Formats const  formats);
 	///
Index: src/Converter.cpp
===
--- src/Converter.cpp	(revision 18380)
+++ src/Converter.cpp	(working copy)
@@ -31,7 +31,6 @@
 #include support/Path.h
 #include support/Systemcall.h
 
-
 namespace lyx {
 
 using support::addName;
@@ -118,7 +117,8 @@
 		 string const  c, string const  l)
 	: from(f), to(t), command(c), flags(l),
 	  From(0), To(0), latex(false), xml(false),
-	  original_dir(false), need_aux(false)
+	  original_dir(false), need_aux(false),
+		use_temp_dir(false)
 {}
 
 
@@ -135,6 +135,8 @@
 			xml = true;
 		else if (flag_name == originaldir)
 			original_dir = true;
+		else if (flag_name == usetempdir)
+			use_temp_dir = true;
 		else if (flag_name == needaux)
 			need_aux = true;
 		else if (flag_name == resultdir)
@@ -293,15 +295,30 @@
  string const  from_format, string const  to_format,
  ErrorList  errorList, int conversionflags)
 {
+	FileName tmp_to_file = to_file;
+	bool trash;
+	return convert(buffer, from_file, tmp_to_file, orig_from, trash,
+	   from_format, to_format, errorList, conversionflags);
+}
+
+
+bool Converters::convert(Buffer const * buffer,
+ FileName const  from_file, FileName  to_file,
+ FileName const  orig_from, bool  used_temp_dir,
+ string const  from_format, string const  to_format,
+ ErrorList  errorList, int conversionflags)
+{
 	if (from_format == to_format)
 		return move(from_format, from_file, to_file, false);
 
-	if ((conversionflags  try_cache) 
-	

[PATCH] Bugs 643, 3047, and 3090

2007-05-18 Thread Richard Heck

The attached patch addresses these bugs, all of which have to do with
export, viewing, and the like---ultimately, with the conversion
routines. The patch introduces a new conversion flag, usetempdir, which
forces the converter to do all its work in a temporary directory created
under the lyx_tmpbuf directory. On export, this directory is copied to
the directory in which the LyX file is contained. So, if you open
/path/file.lyx and File>Export>Format, you will get a directory
/path/file.format.conversion/ in which all the files generated by the
converter will be found (e.g. the mess that htlatex generates ends up in
/path/file.html.conversion/). If you're just viewing, however, you get
$LYXTMPDIR/lyx_tmpbufN/format/, and of course that will get deleted when
LyX exits (gracefully).

As a result, the originaldir flag does not need to be used by any of our
converters, and it may be redundant, though there's no harm leaving it,
so far as I can see.

As you will note, doing this involved adding a new signature to the
Converters::convert() routine. I have not changed any of the other calls
to this: these are in Importer.cpp, insets/InsetGraphics.cpp, and
insets/ExternalSupport.cpp. At least some of these will need modifying
before the patch is applied, probably all of them, as I suppose
usetempdir could be set for importers and graphics converters and such.
There are a few other clean-up type things to be done still, too,
including fixing indentation, but I haven't done that yet as it would
make the diff hard to read.

Comments of course welcome. Will wait to commit for a bit, targeting for
RC1??

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: src/Converter.h
===
--- src/Converter.h	(revision 18380)
+++ src/Converter.h	(working copy)
@@ -59,6 +59,9 @@
 	bool original_dir;
 	/// This converter needs the .aux files
 	bool need_aux;
+	/// This converter should put its files in a separate temporary
+	/// directory
+	bool use_temp_dir;
 	/// If the converter put the result in a directory, then result_dir
 	/// is the name of the directory
 	std::string result_dir;
@@ -123,6 +126,14 @@
 	 support::FileName const & orig_from,
 	 std::string const & from_format, std::string const & to_format,
 	 ErrorList & errorList, int conversionflags = none);
+	/// used_tmp_dir is a flag that signals whether our output files were put into
+	/// a temporary directory. Note also that to_file will be changed so that it points 
+	/// at the converted file in this case.
+	bool convert(Buffer const * buffer,
+	 support::FileName const & from_file, support::FileName & to_file,
+	 support::FileName const & orig_from, bool & used_temp_dir,
+	 std::string const & from_format, std::string const & to_format,
+	 ErrorList & errorList, int conversionflags = none);
 	///
 	void update(Formats const & formats);
 	///
Index: src/Converter.cpp
===
--- src/Converter.cpp	(revision 18380)
+++ src/Converter.cpp	(working copy)
@@ -31,7 +31,6 @@
 #include "support/Path.h"
 #include "support/Systemcall.h"
 
-
 namespace lyx {
 
 using support::addName;
@@ -118,7 +117,8 @@
 		 string const & c, string const & l)
 	: from(f), to(t), command(c), flags(l),
 	  From(0), To(0), latex(false), xml(false),
-	  original_dir(false), need_aux(false)
+	  original_dir(false), need_aux(false),
+		use_temp_dir(false)
 {}
 
 
@@ -135,6 +135,8 @@
 			xml = true;
 		else if (flag_name == "originaldir")
 			original_dir = true;
+		else if (flag_name == "usetempdir")
+			use_temp_dir = true;
 		else if (flag_name == "needaux")
 			need_aux = true;
 		else if (flag_name == "resultdir")
@@ -293,15 +295,30 @@
  string const & from_format, string const & to_format,
  ErrorList & errorList, int conversionflags)
 {
+	FileName tmp_to_file = to_file;
+	bool trash;
+	return convert(buffer, from_file, tmp_to_file, orig_from, trash,
+	   from_format, to_format, errorList, conversionflags);
+}
+
+
+bool Converters::convert(Buffer const * buffer,
+ FileName const & from_file, FileName & to_file,
+ FileName const & orig_from, bool & used_temp_dir,
+ string const & from_format, string const & to_format,
+ ErrorList & errorList, int conversionflags)
+{
 	if (from_format == to_format)
 		return move(from_format, from_file, to_file, false);
 
-	if