http://bugzilla.lyx.org/show_bug.cgi?id=3819

This is a patch from Georg. I tested it and it seems to work for me (there is 
an issue with an assert directly after applying the patch if the file in 
question is already in the cache which can only be solved by emptying the 
cache, see bugzilla).

Here is what Georg has to say about his patch:

"There are two problems:

1) The mover is used incorrectly, therefore it replaces relative paths with
absolute paths in the pstex/pdftex files.

2) pstex/pdftex are special formats: The conversion from fig produces always 
an eps/pdf file as "side effect". LyX (especially the converter machinery) 
does not know about that, therefore these files do not get cached. Export 
does only work because they are listed as referenced files in the external 
template.

The patch fixes the first problem cleanly and the second problem by a quick
hack. This might be good enough for now, but in the long run I think the
referenced file mechanism of the external templates should be replaced by an
augmented format definition: If it is possible for one format to denote 
several files, then the converter machinery (including the cache) could 
handle these cases without any hack, and the definition of new external 
templates would become easier, too."

Opinions?

Jürgen
Index: src/ConverterCache.cpp
===================================================================
--- src/ConverterCache.cpp	(Revision 18950)
+++ src/ConverterCache.cpp	(Arbeitskopie)
@@ -261,6 +261,15 @@
 			     << ' ' << to_format << ' ' << converted_file
 			     << std::endl;
 
+	// FIXME: Should not hardcode this
+	if (to_format == "pstex") {
+		FileName const converted_eps(support::changeExtension(converted_file.absFilename(), "eps"));
+		add(orig_from, "eps", converted_eps);
+	} else if (to_format == "pdftex") {
+		FileName const converted_pdf(support::changeExtension(converted_file.absFilename(), "pdf"));
+		add(orig_from, "pdf", converted_pdf);
+	}
+
 	// Is the file in the cache already?
 	CacheItem * item = pimpl_->find(orig_from, to_format);
 
@@ -286,7 +295,8 @@
 			}
 			item->checksum = checksum;
 		}
-		if (!mover.copy(converted_file, item->cache_name, 0600))
+		if (!mover.copy(converted_file, item->cache_name,
+		                support::onlyFilename(item->cache_name.absFilename()), 0600))
 			LYXERR(Debug::FILES) << "ConverterCache::add("
 					     << orig_from << "):\n"
 						"Could not copy file."
@@ -294,7 +304,8 @@
 	} else {
 		CacheItem new_item(orig_from, to_format, timestamp,
 				support::sum(orig_from));
-		if (mover.copy(converted_file, new_item.cache_name, 0600)) {
+		if (mover.copy(converted_file, new_item.cache_name,
+		               support::onlyFilename(new_item.cache_name.absFilename()), 0600)) {
 			FormatCache & format_cache = pimpl_->cache[orig_from];
 			if (format_cache.from_format.empty())
 				format_cache.from_format =
@@ -418,10 +429,22 @@
 	LYXERR(Debug::FILES) << BOOST_CURRENT_FUNCTION << ' ' << orig_from
 			     << ' ' << to_format << ' ' << dest << std::endl;
 
+	// FIXME: Should not hardcode this
+	if (to_format == "pstex") {
+		FileName const dest_eps(support::changeExtension(dest.absFilename(), "eps"));
+		if (!copy(orig_from, "eps", dest_eps))
+			return false;
+	} else if (to_format == "pdftex") {
+		FileName const dest_pdf(support::changeExtension(dest.absFilename(), "pdf"));
+		if (!copy(orig_from, "pdf", dest_pdf))
+			return false;
+	}
+
 	CacheItem * const item = pimpl_->find(orig_from, to_format);
 	BOOST_ASSERT(item);
 	Mover const & mover = getMover(to_format);
-	return mover.copy(item->cache_name, dest);
+	return mover.copy(item->cache_name, dest,
+	                  support::onlyFilename(dest.absFilename()));
 }
 
 } // namespace lyx

Reply via email to