The attach patch fixes the bug reported this morning by Garst "All ps
figures the same" (and by others over the last month). It also fixes the
bug reported by Konni in Chemnitz that repeated viewings of the dvi file
trigger repeated, and unnecessary, conversions.
Ok to apply?
Angus
ps Have I told anybody what I think of InsetGraphics::prepareFile recently?
;-)
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.807
diff -u -p -r1.807 ChangeLog
--- src/insets/ChangeLog 3 Sep 2003 12:56:52 -0000 1.807
+++ src/insets/ChangeLog 3 Sep 2003 13:03:25 -0000
@@ -1,5 +1,11 @@
2003-09-03 Angus Leeming <[EMAIL PROTECTED]>
+ * insetexternal.C (updateExternal):
+ * insetgraphics.C (prepareFile): Fix the conversion when exporting to
+ latex.
+
+2003-09-03 Angus Leeming <[EMAIL PROTECTED]>
+
* insetexternal.C: don't bring namespace lyx::support into the global
namespace.
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.202
diff -u -p -r1.202 insetgraphics.C
--- src/insets/insetgraphics.C 28 Aug 2003 12:45:51 -0000 1.202
+++ src/insets/insetgraphics.C 3 Sep 2003 13:03:26 -0000
@@ -86,6 +86,7 @@ TODO
// set by Exporters
+namespace support = lyx::support;
using namespace lyx::support;
using std::ostream;
@@ -410,26 +411,54 @@ string const InsetGraphics::prepareFile(
lyxerr[Debug::GRAPHICS]
<< "\tthe orig file is: " << orig_file << endl;
+ bool conversion_needed = true;
if (lyxrc.use_tempdir) {
- temp_file = copyFileToDir(buf.tmppath, orig_file);
- if (temp_file.empty()) {
- string str = bformat(_("Could not copy the file\n%1$s\n"
- "into the temporary directory."),
- orig_file);
- Alert::error(_("Graphics display failed"), str);
- return orig_file;
+ temp_file = MakeAbsPath(FileName(orig_file).mangledFilename(),
+ buf.tmppath);
+ unsigned long const orig_checksum = support::sum(orig_file);
+ unsigned long const temp_checksum = support::sum(temp_file);
+
+ lyxerr << "Checksums " << orig_checksum << ' ' << temp_checksum
+ << std::endl;
+
+ // Nothing to do...
+ if (orig_checksum == temp_checksum) {
+ conversion_needed = false;
+
+ } else {
+ // Cannot proceed...
+ if (!support::copy(orig_file, temp_file)) {
+ string str = bformat(_("Could not copy the file\n%1$s\n"
+ "into the temporary directory."),
+ orig_file);
+ Alert::error(_("Graphics display failed"), str);
+ return orig_file;
+ }
}
+ }
- if (from == to) {
- // No conversion is needed. LaTeX can handle the
- // graphic file as is.
- if (formats.getFormat(to)->extension() == GetExtension(orig_file))
- return RemoveExtension(temp_file);
- return temp_file;
- }
+ if (conversion_needed && from == to) {
+ // No conversion is needed. LaTeX can handle the
+ // graphic file as is.
+ if (formats.getFormat(to)->extension() == GetExtension(orig_file))
+ return RemoveExtension(temp_file);
+ return temp_file;
}
string const outfile_base = RemoveExtension(temp_file);
+ string const to_file = ChangeExtension(outfile_base, to);
+
+ // Do we need to perform the conversion?
+ // Yes if to_file does not exist or if temp_file is newer than to_file
+ if (!conversion_needed ||
+ support::compare_timestamps(temp_file, to_file) < 0) {
+ lyxerr[Debug::GRAPHICS]
+ << bformat(_("No conversion of %1$s is needed after all"),
+ rel_file)
+ << std::endl;
+ return outfile_base;
+ }
+
lyxerr[Debug::GRAPHICS]
<< "\tThe original file is " << orig_file << "\n"
<< "\tA copy has been made and convert is to be called with:\n"
@@ -457,7 +486,7 @@ string const InsetGraphics::prepareFile(
}
}
- return RemoveExtension(temp_file);
+ return outfile_base;
}
Index: src/insets/insetexternal.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetexternal.C,v
retrieving revision 1.98
diff -u -p -r1.98 insetexternal.C
--- src/insets/insetexternal.C 3 Sep 2003 12:56:52 -0000 1.98
+++ src/insets/insetexternal.C 3 Sep 2003 13:03:26 -0000
@@ -518,28 +518,33 @@ void InsetExternal::updateExternal(strin
if (external_in_tmpdir && !from_file.empty()) {
// We are running stuff through LaTeX
- from_file = support::copyFileToDir(buf.tmppath, from_file);
- if (from_file.empty())
+ string const temp_file =
+ support::MakeAbsPath(params_.filename.mangledFilename(),
+ buf.tmppath);
+ unsigned long const from_checksum = support::sum(from_file);
+ unsigned long const temp_checksum = support::sum(temp_file);
+
+ // Nothing to do...
+ if (from_checksum == temp_checksum)
return;
+
+ // Cannot proceed...
+ if (!support::copy(from_file, temp_file))
+ return;
+ from_file = temp_file;
}
string const to_file = doSubstitution(params_, buf,
outputFormat.updateResult);
+ string const abs_to_file = support::MakeAbsPath(to_file, buf.filePath());
- support::FileInfo fi(from_file);
- string abs_to_file = to_file;
- if (!support::AbsolutePath(to_file))
- abs_to_file = support::MakeAbsPath(to_file,
- support::OnlyPath(from_file));
- support::FileInfo fi2(abs_to_file);
- if (fi2.exist() && fi.exist() &&
- difftime(fi2.getModificationTime(),
- fi.getModificationTime()) >= 0) {
- } else {
- string const to_filebase = support::ChangeExtension(to_file, string());
- converters.convert(&buf, from_file, to_filebase,
- from_format, to_format);
- }
+ // Do we need to perform the conversion?
+ // Yes if to_file does not exist or if from_file is newer than to_file
+ if (support::compare_timestamps(from_file, abs_to_file) < 0)
+ return;
+
+ string const to_filebase = support::ChangeExtension(to_file, string());
+ converters.convert(&buf, from_file, to_filebase, from_format, to_format);
}
Index: src/support/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/ChangeLog,v
retrieving revision 1.198
diff -u -p -r1.198 ChangeLog
--- src/support/ChangeLog 3 Sep 2003 12:56:52 -0000 1.198
+++ src/support/ChangeLog 3 Sep 2003 13:03:28 -0000
@@ -1,5 +1,15 @@
2003-09-03 Angus Leeming <[EMAIL PROTECTED]>
+ * filename.[Ch] (FileName): new c-tor takes abs_filename arg.
+ (mangledFilename): new function, returning a mangled version of the
+ absolute file name, suitable for use in the temp dir when, for example,
+ converting an image file to another format.
+
+ * filetools.[Ch] (copyFileToDir): removed.
+ (compare_timestamps): new function.
+
+2003-09-03 Angus Leeming <[EMAIL PROTECTED]>
+
* translator.h: Assert is in namespace lyx::support...
2003-08-02 Jean-Marc Lasgouttes <[EMAIL PROTECTED]>
@@ -22,7 +32,7 @@
2003-07-29 Lars Gullik Bjønnes <[EMAIL PROTECTED]>
- * Makefile.am: contidionalize USE_COMPRESSION
+ * Makefile.am: conditionalize USE_COMPRESSION.
2003-07-28 Lars Gullik Bjønnes <[EMAIL PROTECTED]>
Index: src/support/filename.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filename.C,v
retrieving revision 1.2
diff -u -p -r1.2 filename.C
--- src/support/filename.C 29 Jul 2003 10:56:55 -0000 1.2
+++ src/support/filename.C 3 Sep 2003 13:03:28 -0000
@@ -13,6 +13,8 @@
#include "filename.h"
#include "support/filetools.h"
+#include "lstrings.h"
+#include "LAssert.h"
namespace lyx {
@@ -24,6 +26,13 @@ FileName::FileName()
{}
+FileName::FileName(string const & abs_filename, bool save_abs)
+ : name_(abs_filename), save_abs_path_(save_abs)
+{
+ Assert(AbsolutePath(name_));
+}
+
+
void FileName::set(string const & name, string const & buffer_path)
{
save_abs_path_ = AbsolutePath(name);
@@ -46,6 +55,20 @@ string const FileName::relFilename(strin
string const FileName::outputFilename(string const & path) const
{
return save_abs_path_ ? name_ : MakeRelPath(name_, path);
+}
+
+
+string const FileName::mangledFilename() const
+{
+ string mname = os::slashify_path(name_);
+ // Remove the extension.
+ mname = ChangeExtension(name_, string());
+ // Replace '/' in the file name with '_'
+ mname = subst(mname, "/", "_");
+ // Replace '.' in the file name with '_'
+ mname = subst(mname, ".", "_");
+ // Add the extension back on
+ return ChangeExtension(mname, GetExtension(name_));
}
Index: src/support/filename.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filename.h,v
retrieving revision 1.3
diff -u -p -r1.3 filename.h
--- src/support/filename.h 23 Aug 2003 00:16:57 -0000 1.3
+++ src/support/filename.h 3 Sep 2003 13:03:28 -0000
@@ -22,11 +22,15 @@ namespace support {
class FileName {
public:
FileName();
+ /** \param filename the file in question. Must have an absolute path.
+ * \param save_abs_path how is the file to be output to file?
+ */
+ FileName(string const & abs_filename, bool save_abs_path = true);
/** \param filename the file in question. May have either a relative
- or an absolute path.
- \param buffer_path if \c filename has a relative path, generate
- the absolute path using this.
+ * or an absolute path.
+ * \param buffer_path if \c filename has a relative path, generate
+ * the absolute path using this.
*/
void set(string const & filename, string const & buffer_path);
@@ -39,6 +43,11 @@ public:
string const relFilename(string const & buffer_path = string()) const;
/// \param buf_path if empty, uses `pwd`
string const outputFilename(string const & buf_path = string()) const;
+ /** \return a mangled version of the absolute file name,
+ * suitable for use in the temp dir when, for example, converting
+ * an image file to another format.
+ */
+ string const mangledFilename() const;
private:
string name_;
Index: src/support/filetools.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v
retrieving revision 1.164
diff -u -p -r1.164 filetools.C
--- src/support/filetools.C 28 Jul 2003 22:37:28 -0000 1.164
+++ src/support/filetools.C 3 Sep 2003 13:03:29 -0000
@@ -1333,43 +1333,29 @@ string const readBB_from_PSFile(string c
}
-string const copyFileToDir(string const & path, string const & file_in)
+int compare_timestamps(string const & file1, string const & file2)
{
- Assert(AbsolutePath(path));
-
- // First, make the file path relative to path.
- string file_out = MakeRelPath(path, NormalizePath(file_in));
- file_out = os::slashify_path(file_out);
-
- // Now generate a unique filename.
- // Remove the extension.
- file_out = ChangeExtension(file_out, string());
- // Replace '/' in the file name with '_'
- file_out = subst(file_out, "/", "_");
- // Replace '.' in the file name with '_'
- file_out = subst(file_out, ".", "_");
- // Append a unique ID
-// static int id;
-// file_out += '_' + tostr(id++);
- // Add the extension back on
- file_out = ChangeExtension(file_out, GetExtension(file_in));
- // Put this file in the buffer's temp dir
- file_out = MakeAbsPath(file_out, path);
+ Assert(AbsolutePath(file1) && AbsolutePath(file2));
// If the original is newer than the copy, then copy the original
// to the new directory.
- FileInfo fi(file_in);
- FileInfo fi2(file_out);
+ FileInfo f1(file1);
+ FileInfo f2(file2);
+
+ int cmp = 0;
+ if (f1.exist() && f2.exist()) {
+ double const tmp = difftime(f1.getModificationTime(),
+ f2.getModificationTime());
+ if (tmp != 0)
+ cmp = tmp > 0 ? 1 : -1;
- bool success = true;
- if (fi.exist()) {
- if (!fi2.exist() ||
- difftime(fi.getModificationTime(),
- fi2.getModificationTime()) >= 0)
- success = copy(file_in, file_out);
+ } else if (f1.exist()) {
+ cmp = 1;
+ } else if (f2.exist()) {
+ cmp = -1;
}
- return success ? file_out : string();
+ return cmp;
}
} //namespace support
Index: src/support/filetools.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.h,v
retrieving revision 1.49
diff -u -p -r1.49 filetools.h
--- src/support/filetools.h 23 Aug 2003 00:16:57 -0000 1.49
+++ src/support/filetools.h 3 Sep 2003 13:03:29 -0000
@@ -210,14 +210,14 @@ void removeAutosaveFile(string const & f
/// read the BoundingBox entry from a ps/eps/pdf-file
string const readBB_from_PSFile(string const & file);
-/** Copy \c file to directory \c path. The file name is manipulated
- so that eg some/path/to/file becomes some_path_to_file.
- \param path where to put the file
- \param file the file that is copied
- \returns this file name if the file is copied successfully, else
- \returns an empty string.
+/** \param file1, file2 the two files to be compared. Must have absolute paths.
+ * \returns 1 if \c file1 has a more recent timestamp than \c file2,
+ * 0 if their timestamps are the same,
+ * -1 if \c file2 has a more recent timestamp than \c file1.
+ * If one of the files does not exist, the return value indicates the file
+ * which does exist. Eg, if \c file1 exists but \c file2 does not, return 1.
*/
-string const copyFileToDir(string const & path, string const & file);
+int compare_timestamps(string const & file1, string const & file2);
typedef std::pair<int, string> cmd_ret;