The graphics cache decompresses zipped files in place for preview, that
means it will overwrite a.eps without warning if a.eps.gz is included in
the LyX file.
The attached patch changes that: The unzipped file is put into the temp dir.
The patch is against 1.4, but a similar one should work for 1.3, too.


Georg
Index: src/graphics/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/graphics/ChangeLog,v
retrieving revision 1.199
diff -u -r1.199 ChangeLog
--- src/graphics/ChangeLog	2004/01/31 15:30:23	1.199
+++ src/graphics/ChangeLog	2004/02/02 13:10:17
@@ -1,3 +1,8 @@
+2004-02-02  Georg Baum  <[EMAIL PROTECTED]>
+
+	* GraphicsCacheItem.C (convertToDisplayFormat): unzip zipped files
+	to a temporary file
+
 2004-01-31  Lars Gullik Bjonnes  <[EMAIL PROTECTED]>
 
 	* PreviewLoader.C (FindFirst): inherit from std::unary_function
Index: src/graphics/GraphicsCacheItem.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/graphics/GraphicsCacheItem.C,v
retrieving revision 1.60
diff -u -r1.60 GraphicsCacheItem.C
--- src/graphics/GraphicsCacheItem.C	2003/10/06 15:42:58	1.60
+++ src/graphics/GraphicsCacheItem.C	2004/02/02 13:10:17
@@ -35,6 +39,7 @@
 using support::getExtFromContents;
 using support::tempName;
 using support::unlink;
+using support::unzippedFileName;
 using support::unzipFile;
 using support::zippedFile;
 
@@ -381,8 +387,13 @@
 	}
 
 	// Make a local copy in case we unzip it
-	string const filename = zippedFile(filename_) ?
-		unzipFile(filename_) : filename_;
+	string filename;
+	if ((zipped_ = zippedFile(filename_))) {
+		unzipped_filename_ = tempName(string(), filename_);
+		filename = unzipFile(filename_, unzipped_filename_);
+	} else
+		filename = filename_;
+
 	string const displayed_filename = MakeDisplayPath(filename_);
 	lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n"
 		<< "\tAttempting to convert image file: " << filename
@@ -412,6 +423,7 @@
 	remove_loaded_file_ = true;
 
 	// Remove the temp file, we only want the name...
+	// FIXME: This is unsafe!
 	unlink(to_file_base);
 
 	// Connect a signal to this->imageConverted and pass this signal to
Index: src/support/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/support/ChangeLog,v
retrieving revision 1.237
diff -u -r1.237 ChangeLog
--- src/support/ChangeLog	2004/02/01 12:46:13	1.237
+++ src/support/ChangeLog	2004/02/02 13:20:14
@@ -1,3 +1,7 @@
+2004-02-02  Georg Baum  <[EMAIL PROTECTED]>
+
+	* filetools.[Ch] (unzipFile): add unzipped_file parameter
+
 2004-02-01  Lars Gullik Bjonnes  <[EMAIL PROTECTED]>
 
 	* lstrings.h (contains_functor): delete
Index: src/support/filetools.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/support/filetools.C,v
retrieving revision 1.176
diff -u -r1.176 filetools.C
--- src/support/filetools.C	2003/10/16 16:41:32	1.176
+++ src/support/filetools.C	2004/02/02 13:10:28
@@ -1080,9 +1080,10 @@
 }
 
 
-string const unzipFile(string const & zipped_file)
+string const unzipFile(string const & zipped_file, string const & unzipped_file)
 {
-	string  const tempfile = unzippedFileName(zipped_file);
+	string const tempfile = unzipped_file.empty() ?
+		unzippedFileName(zipped_file) : unzipped_file;
 	// Run gunzip
 	string const command = "gunzip -c " + zipped_file + " > " + tempfile;
 	Systemcall one;
Index: src/support/filetools.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/support/filetools.h,v
retrieving revision 1.53
diff -u -r1.53 filetools.h
--- src/support/filetools.h	2003/10/06 15:43:18	1.53
+++ src/support/filetools.h	2004/02/02 13:10:28
@@ -141,11 +141,18 @@
 /// check for zipped file
 bool zippedFile(std::string const & name);
 
-/// \return the name that LyX will give to the unzipped file.
+/** \return the name that LyX will give to the unzipped file \p zipped_file
+  if the second argument of unzipFile() is empty.
+ */
 std::string const unzippedFileName(std::string const & zipped_file);
 
-/// unzip a file
-std::string const unzipFile(std::string const & zipped_file);
+/** Unzip \p zipped_file.
+   The unzipped file is named \p unzipped_file if \p unzipped_file is not
+   empty, and unzippedFileName(\p zipped_file) otherwise.
+   Will overwrite an already existing unzipped file without warning.
+ */
+std::string const unzipFile(std::string const & zipped_file,
+                            std::string const & unzipped_file = std::string());
 
 /// Returns true is path is absolute
 bool AbsolutePath(std::string const & path);

Reply via email to