| 100 | } |
| 101 | |
| 102 | void FileRegister::removeOriginMulti(std::set<FileIndex> indices, OriginID originID) |
| 103 | { |
| 104 | std::vector<FileEntryPtr> removedFiles; |
| 105 | |
| 106 | { |
| 107 | std::scoped_lock lock(m_Mutex); |
| 108 | |
| 109 | for (auto iter = indices.begin(); iter != indices.end();) { |
| 110 | const auto index = *iter; |
| 111 | |
| 112 | if (index < m_Files.size()) { |
| 113 | const auto& p = m_Files[index]; |
| 114 | |
| 115 | if (p && p->removeOrigin(originID)) { |
| 116 | removedFiles.push_back(p); |
| 117 | m_Files[index] = {}; |
| 118 | ++iter; |
| 119 | continue; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | iter = indices.erase(iter); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // optimization: this is only called when disabling an origin and in this case |
| 128 | // we don't have to remove the file from the origin |
| 129 | |
| 130 | // need to remove files from their parent directories. multiple ways to go |
| 131 | // about this: |
| 132 | // a) for each file, search its parents file-list (preferably by name) and |
| 133 | // remove what is found |
| 134 | // b) gather the parent directories, go through the file list for each once |
| 135 | // and remove all files that have been removed |
| 136 | // |
| 137 | // the latter should be faster when there are many files in few directories. |
| 138 | // since this is called only when disabling an origin that is probably |
| 139 | // frequently the case |
| 140 | |
| 141 | std::set<DirectoryEntry*> parents; |
| 142 | for (const FileEntryPtr& file : removedFiles) { |
| 143 | if (file->getParent() != nullptr) { |
| 144 | parents.insert(file->getParent()); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | for (DirectoryEntry* parent : parents) { |
| 149 | parent->removeFiles(indices); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void FileRegister::sortOrigins() |
| 154 | { |
no test coverage detected