mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +00:00
xHTML export: change filenames of exported images.
This patch aims at: 1. replacing absolute paths by their hashes (do not leak directory structures) 2. not using counters anymore so that changing figures order in the document does not lead to large number of obsolete images in export directory. Other changes than in xHTML export of images are unintended.
This commit is contained in:
parent
50f8ed4169
commit
eef0c8e8ed
@ -575,7 +575,7 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir)
|
|||||||
if (rtrim(only_path, "/") == rtrim(dir, "/"))
|
if (rtrim(only_path, "/") == rtrim(dir, "/"))
|
||||||
return make_pair(IDENTICAL_PATHS, FileName(file_in));
|
return make_pair(IDENTICAL_PATHS, FileName(file_in));
|
||||||
|
|
||||||
string mangled = file.mangledFileName();
|
string mangled = file.mangledFileName(empty_string(), false, true);
|
||||||
if (theFormats().isZippedFile(file)) {
|
if (theFormats().isZippedFile(file)) {
|
||||||
// We need to change _eps.gz to .eps.gz. The mangled name is
|
// We need to change _eps.gz to .eps.gz. The mangled name is
|
||||||
// still unique because of the counter in mangledFileName().
|
// still unique because of the counter in mangledFileName().
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "support/Package.h"
|
#include "support/Package.h"
|
||||||
#include "support/qstring_helpers.h"
|
#include "support/qstring_helpers.h"
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -955,6 +956,11 @@ string DocFileName::outputFileName(string const & path) const
|
|||||||
|
|
||||||
|
|
||||||
string DocFileName::mangledFileName(string const & dir) const
|
string DocFileName::mangledFileName(string const & dir) const
|
||||||
|
{
|
||||||
|
return mangledFileName(dir, true, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
string DocFileName::mangledFileName(string const & dir, bool use_counter, bool encrypt_path) const
|
||||||
{
|
{
|
||||||
// Concurrent access to these variables is possible.
|
// Concurrent access to these variables is possible.
|
||||||
|
|
||||||
@ -972,6 +978,19 @@ string DocFileName::mangledFileName(string const & dir) const
|
|||||||
string const name = absFileName();
|
string const name = absFileName();
|
||||||
// Now the real work. Remove the extension.
|
// Now the real work. Remove the extension.
|
||||||
string mname = support::changeExtension(name, string());
|
string mname = support::changeExtension(name, string());
|
||||||
|
|
||||||
|
if (encrypt_path) {
|
||||||
|
QString qname = toqstr(mname);
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
QByteArray hash = QCryptographicHash::hash(qname.toLocal8Bit(),QCryptographicHash::Sha256);
|
||||||
|
#else
|
||||||
|
QByteArray hash = QCryptographicHash::hash(qname.toLocal8Bit(),QCryptographicHash::Sha1);
|
||||||
|
#endif
|
||||||
|
hash = hash.toHex();
|
||||||
|
mname = fromqstr(QString(hash));
|
||||||
|
mname = mname + "_" + onlyFileName();
|
||||||
|
}
|
||||||
|
|
||||||
// The mangled name must be a valid LaTeX name.
|
// The mangled name must be a valid LaTeX name.
|
||||||
// The list of characters to keep is probably over-restrictive,
|
// The list of characters to keep is probably over-restrictive,
|
||||||
// but it is not really a problem.
|
// but it is not really a problem.
|
||||||
@ -991,9 +1010,12 @@ string DocFileName::mangledFileName(string const & dir) const
|
|||||||
// Prepend a counter to the filename. This is necessary to make
|
// Prepend a counter to the filename. This is necessary to make
|
||||||
// the mangled name unique.
|
// the mangled name unique.
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
|
||||||
|
if (use_counter) {
|
||||||
ostringstream s;
|
ostringstream s;
|
||||||
s << counter++ << mname;
|
s << counter++ << mname;
|
||||||
mname = s.str();
|
mname = s.str();
|
||||||
|
}
|
||||||
|
|
||||||
// MiKTeX's YAP (version 2.4.1803) crashes if the file name
|
// MiKTeX's YAP (version 2.4.1803) crashes if the file name
|
||||||
// is longer than about 160 characters. MiKTeX's pdflatex
|
// is longer than about 160 characters. MiKTeX's pdflatex
|
||||||
|
@ -291,6 +291,14 @@ public:
|
|||||||
std::string
|
std::string
|
||||||
mangledFileName(std::string const & dir = empty_string()) const;
|
mangledFileName(std::string const & dir = empty_string()) const;
|
||||||
|
|
||||||
|
/** Identical to mangledFileName, wit the following additions:
|
||||||
|
*
|
||||||
|
* @encrypt_path allows using hash (SHA-256) instead of full path.
|
||||||
|
* @use_counter allows disabling the counter in the filename.
|
||||||
|
*/
|
||||||
|
std::string
|
||||||
|
mangledFileName(std::string const & dir, bool use_counter, bool encrypt_path) const;
|
||||||
|
|
||||||
/// \return the absolute file name without its .gz, .z, .Z extension
|
/// \return the absolute file name without its .gz, .z, .Z extension
|
||||||
std::string unzippedFileName() const;
|
std::string unzippedFileName() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user