MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / recoverFromTrash

Method recoverFromTrash

src/common/util/processutil.cpp:141–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141bool ProcessUtil::recoverFromTrash(const QString &filePath)
142{
143#ifdef linux
144 if (!hasGio() || filePath.isEmpty())
145 return false;
146
147 QDirIterator itera(QDir::homePath() + QDir::separator() + ".local/share/Trash/files");
148 while (itera.hasNext()){
149 itera.next();
150 QFileInfo info(filePath);
151 if(info.suffix() == itera.fileInfo().suffix()
152 && info.baseName() == itera.fileInfo().baseName()) {
153 QByteArray readArray;
154 auto readCB = [&](const QByteArray array){readArray = array;};
155 QString trashFileUri = QString("trash:///%0").arg(info.fileName());
156 QStringList queryArgs;
157 queryArgs << "info";
158 queryArgs << trashFileUri;
159 queryArgs << "| grep trash::orig-path";
160 bool execResult = ProcessUtil::execute("gio", queryArgs, readCB);
161 if (!execResult && readArray.isEmpty()) {
162 qCritical() << "Unknown Error";
163 abort();
164 }
165 readArray = readArray.replace(" ", "");
166 auto list = readArray.split('\n');
167 auto itera = list.rbegin();
168 while (itera != list.rend()) {
169 if (itera->startsWith("trash::orig-path:")) {
170 readArray = *itera;
171 break;
172 }
173 itera ++;
174 }
175 if (!readArray.startsWith("trash::orig-path:")) {
176 qCritical() << "Error from: " <<QString::fromUtf8(readArray);
177 abort();
178 }
179 readArray = readArray.replace("trash::orig-path:", "");
180 if (readArray == filePath) {
181 QStringList args;
182 args << "move";
183 args << trashFileUri;
184 args << QUrl::fromLocalFile(filePath).toString();
185 return ProcessUtil::execute("gio", args);
186 }
187 }
188 }
189
190#else
191
192#endif
193 return false;
194}
195
196bool ProcessUtil::portOverhead(unsigned int port)
197{

Callers

nothing calls this directly

Calls 8

abortFunction · 0.85
fileNameMethod · 0.80
startsWithMethod · 0.80
QStringClass · 0.70
isEmptyMethod · 0.45
nextMethod · 0.45
replaceMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected