os << std::setw(10) << std::setfill('0') << do_crc(orig_from.absFilename())
<< '-' << to_format;
cache_name = FileName(addName(cache_dir.absFilename(), os.str()));
- lyxerr[Debug::FILES] << "Add file cache item " << orig_from
+ LYXERR(Debug::FILES) << "Add file cache item " << orig_from
<< ' ' << to_format << ' ' << cache_name
<< ' ' << timestamp << ' ' << checksum
<< '.' << std::endl;
CacheItem item(orig_from_name, to_format, timestamp, checksum);
// Don't cache files that do not exist anymore
- if (!fs::exists(orig_from)) {
- lyxerr[Debug::FILES] << "Not caching file `"
+ if (!fs::exists(orig_from_name.toFilesystemEncoding())) {
+ LYXERR(Debug::FILES) << "Not caching file `"
<< orig_from << "' (does not exist anymore)."
<< std::endl;
support::unlink(item.cache_name);
// Delete the cached file if it is too old
if (difftime(now, fs::last_write_time(item.cache_name.toFilesystemEncoding())) >
lyxrc.converter_cache_maxage) {
- lyxerr[Debug::FILES] << "Not caching file `"
+ LYXERR(Debug::FILES) << "Not caching file `"
<< orig_from << "' (too old)." << std::endl;
support::unlink(item.cache_name);
continue;
return;
// We do this here and not in the constructor because package() gets
// initialized after all static variables.
- cache_dir = FileName(addName(support::package().user_support(), "cache"));
+ cache_dir = FileName(addName(support::package().user_support().absFilename(), "cache"));
if (!fs::exists(cache_dir.toFilesystemEncoding()))
if (support::mkdir(cache_dir, 0700) != 0) {
lyxerr << "Could not create cache directory `"
void ConverterCache::add(FileName const & orig_from, string const & to_format,
FileName const & converted_file) const
{
- if (!lyxrc.use_converter_cache)
+ if (!lyxrc.use_converter_cache || orig_from.empty() ||
+ converted_file.empty())
return;
- lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
+ LYXERR(Debug::FILES) << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << ' ' << converted_file
<< std::endl;
CacheItem * item = pimpl_->find(orig_from, to_format);
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
- Mover const & mover = movers(to_format);
+ Mover const & mover = getMover(to_format);
if (item) {
- lyxerr[Debug::FILES] << "ConverterCache::add(" << orig_from << "):\n"
+ LYXERR(Debug::FILES) << "ConverterCache::add(" << orig_from << "):\n"
"The file is already in the cache."
<< std::endl;
// First test for timestamp
if (timestamp == item->timestamp) {
- lyxerr[Debug::FILES] << "Same timestamp."
+ LYXERR(Debug::FILES) << "Same timestamp."
<< std::endl;
return;
} else {
item->timestamp = timestamp;
unsigned long const checksum = support::sum(orig_from);
if (checksum == item->checksum) {
- lyxerr[Debug::FILES] << "Same checksum."
+ LYXERR(Debug::FILES) << "Same checksum."
<< std::endl;
return;
}
item->checksum = checksum;
}
if (!mover.copy(converted_file, item->cache_name, 0600))
- lyxerr[Debug::FILES] << "ConverterCache::add("
+ LYXERR(Debug::FILES) << "ConverterCache::add("
<< orig_from << "):\n"
"Could not copy file."
<< std::endl;
if (mover.copy(converted_file, new_item.cache_name, 0600))
pimpl_->cache[orig_from][to_format] = new_item;
else
- lyxerr[Debug::FILES] << "ConverterCache::add("
+ LYXERR(Debug::FILES) << "ConverterCache::add("
<< orig_from << "):\n"
"Could not copy file."
<< std::endl;
void ConverterCache::remove(FileName const & orig_from,
string const & to_format) const
{
- if (!lyxrc.use_converter_cache)
+ if (!lyxrc.use_converter_cache || orig_from.empty())
return;
- lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
+ LYXERR(Debug::FILES) << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << std::endl;
CacheType::iterator const it1 = pimpl_->cache.find(orig_from);
bool ConverterCache::inCache(FileName const & orig_from,
string const & to_format) const
{
- if (!lyxrc.use_converter_cache)
+ if (!lyxrc.use_converter_cache || orig_from.empty())
return false;
- lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
+ LYXERR(Debug::FILES) << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << std::endl;
CacheItem * const item = pimpl_->find(orig_from, to_format);
if (!item) {
- lyxerr[Debug::FILES] << "not in cache." << std::endl;
+ LYXERR(Debug::FILES) << "not in cache." << std::endl;
return false;
}
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
if (item->timestamp == timestamp) {
- lyxerr[Debug::FILES] << "identical timestamp." << std::endl;
+ LYXERR(Debug::FILES) << "identical timestamp." << std::endl;
return true;
}
if (item->checksum == support::sum(orig_from)) {
item->timestamp = timestamp;
- lyxerr[Debug::FILES] << "identical checksum." << std::endl;
+ LYXERR(Debug::FILES) << "identical checksum." << std::endl;
return true;
}
- lyxerr[Debug::FILES] << "in cache, but too old." << std::endl;
+ LYXERR(Debug::FILES) << "in cache, but too old." << std::endl;
return false;
}
FileName const & ConverterCache::cacheName(FileName const & orig_from,
string const & to_format) const
{
- lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
+ LYXERR(Debug::FILES) << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << std::endl;
CacheItem * const item = pimpl_->find(orig_from, to_format);
bool ConverterCache::copy(FileName const & orig_from, string const & to_format,
FileName const & dest) const
{
- if (!lyxrc.use_converter_cache)
+ if (!lyxrc.use_converter_cache || orig_from.empty() || dest.empty())
return false;
- lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
+ LYXERR(Debug::FILES) << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << ' ' << dest << std::endl;
CacheItem * const item = pimpl_->find(orig_from, to_format);
BOOST_ASSERT(item);
- Mover const & mover = movers(to_format);
+ Mover const & mover = getMover(to_format);
return mover.copy(item->cache_name, dest);
}