diskmanager: fixed issues regarding frame deletion
This commit is contained in:
@@ -214,10 +214,10 @@ bool DiskCacheFolder::ClearCache()
|
||||
|
||||
while (i != disk_data_.end()) {
|
||||
// We return a false result if any of the files fail to delete, but still try to delete as many as we can
|
||||
const QString &filename = i.key();
|
||||
QString filename = i.key();
|
||||
|
||||
if (QFile::remove(filename) || !QFileInfo::exists(filename)) {
|
||||
emit DeletedFrame(path_, i.key());
|
||||
emit DeletedFrame(path_, filename);
|
||||
i = disk_data_.erase(i);
|
||||
} else {
|
||||
qWarning() << "Failed to delete" << filename;
|
||||
@@ -308,11 +308,15 @@ void DiskCacheFolder::SetPath(const QString &path)
|
||||
bool DiskCacheFolder::DeleteFileInternal(QMap<QString, HashTime>::iterator hash_to_delete)
|
||||
{
|
||||
// Cache HashTime object
|
||||
const QString &filename = hash_to_delete.key();
|
||||
QString filename = hash_to_delete.key();
|
||||
HashTime ht = hash_to_delete.value();
|
||||
|
||||
// Remove from disk
|
||||
if (QFile::remove(filename)) {
|
||||
QFile f(filename);
|
||||
|
||||
if (!f.exists()) {
|
||||
return true;
|
||||
} else if (f.remove()) {
|
||||
// Remove from internal map
|
||||
disk_data_.erase(hash_to_delete);
|
||||
|
||||
@@ -342,11 +346,12 @@ bool DiskCacheFolder::DeleteLeastRecent()
|
||||
{
|
||||
auto hash_to_delete = disk_data_.begin();
|
||||
|
||||
for (auto it=disk_data_.begin()+1; it!=disk_data_.end(); it++) {
|
||||
if (it->access_time < hash_to_delete->access_time) {
|
||||
hash_to_delete = it;
|
||||
if (disk_data_.begin() != disk_data_.end()) {
|
||||
for (auto it=disk_data_.begin()+1; it!=disk_data_.end(); it++) {
|
||||
if (it->access_time < hash_to_delete->access_time) {
|
||||
hash_to_delete = it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DeleteFileInternal(hash_to_delete);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ bool FrameHashCache::SaveCacheFrame(const QString &cache_path, const QUuid &uuid
|
||||
|
||||
// Register frame with the disk manager
|
||||
if (ret) {
|
||||
DiskManager::instance()->CreatedFile(cache_path, fn);
|
||||
QMetaObject::invokeMethod(DiskManager::instance(), "CreatedFile", Q_ARG(QString, cache_path), Q_ARG(QString, fn));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -102,7 +102,7 @@ bool FrameHashCache::SaveCacheFrame(const QString &cache_path, const QUuid &uuid
|
||||
|
||||
// Register frame with the disk manager
|
||||
if (ret) {
|
||||
DiskManager::instance()->CreatedFile(cache_path, fn);
|
||||
QMetaObject::invokeMethod(DiskManager::instance(), "CreatedFile", Q_ARG(QString, cache_path), Q_ARG(QString, fn));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -186,7 +186,7 @@ FramePtr FrameHashCache::LoadCacheFrame(const QString &fn)
|
||||
frame = nullptr;
|
||||
|
||||
// Assume this frame is corrupt in some way and delete it
|
||||
DiskManager::instance()->DeleteSpecificFile(fn);
|
||||
QMetaObject::invokeMethod(DiskManager::instance(), "DeleteSpecificFile", Q_ARG(QString, fn));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -242,7 +242,9 @@ QString FrameHashCache::CachePathName(const QString &cache_path, const QUuid &ca
|
||||
QString filename = QDir(QDir(cache_path).filePath(cache_id.toString())).filePath(QString::number(time));
|
||||
|
||||
// Register that in some way this hash has been accessed
|
||||
DiskManager::instance()->Accessed(cache_path, filename);
|
||||
if (DiskManager::instance()) {
|
||||
QMetaObject::invokeMethod(DiskManager::instance(), "Accessed", Q_ARG(QString, cache_path), Q_ARG(QString, filename));
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user