MCPcopy Create free account
hub / github.com/MultiMC/Launcher / deletePath

Function deletePath

launcher/FileSystem.cpp:174–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174bool deletePath(QString path)
175{
176 bool OK = true;
177 QFileInfo finfo(path);
178 if(finfo.isFile()) {
179 return QFile::remove(path);
180 }
181
182 QDir dir(path);
183
184 if (!dir.exists())
185 {
186 return OK;
187 }
188 auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
189 QDir::AllDirs | QDir::Files,
190 QDir::DirsFirst);
191
192 for(auto & info: allEntries)
193 {
194#if defined Q_OS_WIN32
195 QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath());
196 auto wString = nativePath.toStdWString();
197 DWORD dwAttrs = GetFileAttributesW(wString.c_str());
198 // Windows: check for junctions, reparse points and other nasty things of that sort
199 if(dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT)
200 {
201 if (info.isFile())
202 {
203 OK &= QFile::remove(info.absoluteFilePath());
204 }
205 else if (info.isDir())
206 {
207 OK &= dir.rmdir(info.absoluteFilePath());
208 }
209 }
210#else
211 // We do not trust Qt with reparse points, but do trust it with unix symlinks.
212 if(info.isSymLink())
213 {
214 OK &= QFile::remove(info.absoluteFilePath());
215 }
216#endif
217 else if (info.isDir())
218 {
219 OK &= deletePath(info.absoluteFilePath());
220 }
221 else if (info.isFile())
222 {
223 OK &= QFile::remove(info.absoluteFilePath());
224 }
225 else
226 {
227 OK = false;
228 qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath();
229 }
230 }
231 OK &= dir.rmdir(dir.absolutePath());

Callers 7

processFlameMethod · 0.85
installUpdatesMethod · 0.85
deleteInstanceMethod · 0.85
destroyStagingPathMethod · 0.85
installMethod · 0.85
copyFinishedMethod · 0.85
destroyMethod · 0.85

Calls 1

existsMethod · 0.80

Tested by

no test coverage detected