Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/trash/trashsizecache.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | void TrashSizeCache::clear() | 93 | void TrashSizeCache::clear() | ||
94 | { | 94 | { | ||
95 | QFile::remove(mTrashSizeCachePath); | 95 | QFile::remove(mTrashSizeCachePath); | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | struct CacheData { | 98 | struct CacheData { | ||
99 | qint64 mtime; | | |||
100 | qulonglong size; | 99 | qulonglong size; | ||
100 | qint64 mtime; | ||||
101 | }; | 101 | }; | ||
102 | 102 | | |||
103 | qulonglong TrashSizeCache::calculateSize() | 103 | qulonglong TrashSizeCache::calculateSize() | ||
104 | { | 104 | { | ||
105 | // First read the directorysizes cache into memory | 105 | // First read the directorysizes cache into memory | ||
106 | QFile file(mTrashSizeCachePath); | 106 | QFile file(mTrashSizeCachePath); | ||
107 | typedef QHash<QByteArray, CacheData> DirCacheHash; | 107 | typedef QHash<QByteArray, CacheData> DirCacheHash; | ||
108 | DirCacheHash dirCache; | 108 | DirCacheHash dirCache; | ||
109 | if (file.open(QIODevice::ReadOnly)) { | 109 | if (file.open(QIODevice::ReadOnly)) { | ||
110 | while (!file.atEnd()) { | 110 | while (!file.atEnd()) { | ||
111 | const QByteArray line = file.readLine(); | 111 | const QByteArray line = file.readLine(); | ||
112 | const int firstSpace = line.indexOf(' '); | 112 | const int firstSpace = line.indexOf(' '); | ||
113 | const int secondSpace = line.indexOf(' ', firstSpace + 1); | 113 | const int secondSpace = line.indexOf(' ', firstSpace + 1); | ||
114 | CacheData data; | 114 | CacheData data; | ||
115 | data.mtime = line.left(firstSpace).toLongLong(); | 115 | data.size = line.left(firstSpace).toULongLong(); | ||
116 | // "012 4567 name" -> firstSpace=3, secondSpace=8, we want mid(4,4) | 116 | // "012 4567 name" -> firstSpace=3, secondSpace=8, we want mid(4,4) | ||
117 | data.size = line.mid(firstSpace + 1, secondSpace - firstSpace - 1).toULongLong(); | 117 | data.mtime = line.mid(firstSpace + 1, secondSpace - firstSpace - 1).toLongLong(); | ||
118 | dirCache.insert(line.mid(secondSpace + 1), data); | 118 | dirCache.insert(line.mid(secondSpace + 1), data); | ||
119 | } | 119 | } | ||
120 | } | 120 | } | ||
121 | // Iterate over the actual trashed files. | 121 | // Iterate over the actual trashed files. | ||
122 | // Orphan items (no .fileinfo) still take space. | 122 | // Orphan items (no .fileinfo) still take space. | ||
123 | QDirIterator it(mTrashPath + QLatin1String("/files/"), QDirIterator::NoIteratorFlags); | 123 | QDirIterator it(mTrashPath + QLatin1String("/files/"), QDirIterator::NoIteratorFlags); | ||
124 | 124 | | |||
125 | qulonglong sum = 0; | 125 | qulonglong sum = 0; | ||
Show All 34 Lines |