#include <QFileInfo>
#include <QList>
#include <QTemporaryFile>
-#include <QTime>
+#include <QElapsedTimer>
+
+#ifdef _WIN32
+#include <QThread>
+#endif
#include <boost/crc.hpp>
{
Private() {}
- Private(string const & abs_filename) : fi(toqstr(handleTildeName(abs_filename)))
+ explicit Private(string const & abs_filename)
+ : fi(toqstr(handleTildeName(abs_filename)))
{
name = fromqstr(fi.absoluteFilePath());
fi.setCaching(fi.exists() ? true : false);
{
LYXERR(Debug::FILES, "Renaming " << name << " as " << *this);
bool success = QFile::rename(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
+ d->refresh();
if (!success)
LYXERR0("Could not rename file " << *this << " to " << name);
return success;
bool FileName::moveTo(FileName const & name) const
{
LYXERR(Debug::FILES, "Moving " << *this << " to " << name);
+#ifdef _WIN32
+ // there's a locking problem on Windows sometimes, so
+ // we will keep trying for five seconds, in the hope
+ // that clears.
+ name.refresh();
+ if (name.exists()) {
+ bool removed = name.removeFile();
+ int tries = 1;
+ while (!removed && tries < 6) {
+ QThread::sleep(1);
+ removed = name.removeFile();
+ tries++;
+ }
+ }
+#else
QFile::remove(name.d->fi.absoluteFilePath());
+#endif
- bool success = QFile::rename(d->fi.absoluteFilePath(),
- name.d->fi.absoluteFilePath());
+ bool const success = renameTo(name);
if (!success)
LYXERR0("Could not move file " << *this << " to " << name);
return success;
unsigned long FileName::checksum() const
{
- unsigned long result = 0;
-
if (!exists()) {
//LYXERR0("File \"" << absFileName() << "\" does not exist!");
- return result;
+ return 0;
}
// a directory may be passed here so we need to test it. (bug 3622)
if (isDirectory()) {
LYXERR0('"' << absFileName() << "\" is a directory!");
- return result;
+ return 0;
}
// This is used in the debug output at the end of the method.
- static QTime t;
+ static QElapsedTimer t;
if (lyxerr.debugging(Debug::FILES))
t.restart();
+ unsigned long result = 0;
+
#if QT_VERSION >= 0x999999
// First version of checksum uses Qt4.4 mmap support.
// FIXME: This code is not ready with Qt4.4.2,
// QAbstractFileEngine::MapExtension)
QFile qf(fi.filePath());
if (!qf.open(QIODevice::ReadOnly))
- return result;
+ return 0;
qint64 size = fi.size();
uchar * ubeg = qf.map(0, size);
uchar * uend = ubeg + size;
int fd = open(file, O_RDONLY);
if (!fd)
- return result;
+ return 0;
struct stat info;
if (fstat(fd, &info)){
// Some platforms have the wrong type for MAP_FAILED (compaq cxx).
if (mm == reinterpret_cast<void*>(MAP_FAILED)) {
close(fd);
- return result;
+ return 0;
}
char * beg = static_cast<char*>(mm);
return (*it).second;
string const name = absFileName();
- // Now the real work
- string mname = os::internal_path(name);
- // Remove the extension.
- mname = support::changeExtension(name, string());
+ // Now the real work. Remove the extension.
+ string mname = support::changeExtension(name, string());
// The mangled name must be a valid LaTeX name.
// The list of characters to keep is probably over-restrictive,
// but it is not really a problem.