Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/dfm-io/dfm-io/denumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool DEnumeratorPrivate::checkNameFilter(const QString &fileName)
bool DEnumeratorPrivate::openDirByfts()
{
char *paths[2] = { nullptr, nullptr };
paths[0] = filePath(uri);
paths[0] = strdup(filePath(uri).constData());
if (!paths[0]) {
error.setCode(DFMIOErrorCode::DFM_IO_ERROR_FAILED);
return false;
Expand Down Expand Up @@ -433,15 +433,15 @@ void DEnumeratorPrivate::setQueryAttributes(const QString &attributes)
queryAttributes = attributes;
}

char *DEnumeratorPrivate::filePath(const QUrl &url)
QByteArray DEnumeratorPrivate::filePath(const QUrl &url)
{
if (url.userInfo().startsWith("originPath::"))
return strdup(url.userInfo().replace("originPath::", "").toLatin1().constData());
return url.userInfo().replace("originPath::", "").toLatin1();

QString path = url.path();
if (path != "/" && path.endsWith("/"))
path = path.left(path.length() - 1);
return strdup(path.toUtf8().constData());
return path.toUtf8();
}

QUrl DEnumeratorPrivate::buildUrl(const QUrl &url, const char *fileName)
Expand Down Expand Up @@ -831,11 +831,8 @@ QList<QSharedPointer<DEnumerator::SortFileInfo>> DEnumerator::sortFileInfoList()
QSet<QString> hideList;
QUrl urlHidden = d->buildUrl(d->uri, ".hidden");
hideList = DLocalHelper::hideListFromUrl(urlHidden);
char *dirPath = d->filePath(d->uri);
if (!dirPath) {
qWarning() << "Failed to get file path for uri:" << d->uri;
return {};
}
QByteArray dirPathBa = d->filePath(d->uri);
const char *dirPath = dirPathBa.constData();
while (1) {
FTSENT *ent = fts_read(d->fts);

Expand All @@ -857,8 +854,6 @@ QList<QSharedPointer<DEnumerator::SortFileInfo>> DEnumerator::sortFileInfoList()
fts_close(d->fts);
d->fts = nullptr;

// Clean up allocated memory
free(dirPath);

if (d->isMixDirAndFile)
return listFile;
Expand Down
2 changes: 1 addition & 1 deletion src/dfm-io/dfm-io/private/denumerator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DEnumeratorPrivate : public QObject, public QEnableSharedFromThis<DEnumera
bool hasNext();
QList<QSharedPointer<DFileInfo>> fileInfoList();
void setQueryAttributes(const QString &attributes);
char *filePath(const QUrl &url);
QByteArray filePath(const QUrl &url);
QUrl buildUrl(const QUrl &url, const char *fileName);

static void enumUriAsyncCallBack(GObject *sourceObject,
Expand Down
Loading