Commit 228e1519 authored by David Faure's avatar David Faure
Browse files

Fix listRecursive so that display names get parent dirs prepended too.

The list of names was d1/d2/file, and the list of display-names was just "file",
leading to flattening out directory structures when setting up kioslaves with
fileNameUsedForCopying=DisplayName.
CCBUG: 183403
parent 363ae4a7
......@@ -2472,14 +2472,17 @@ SimpleJob *KIO::file_delete( const KUrl& src, JobFlags flags )
class KIO::ListJobPrivate: public KIO::SimpleJobPrivate
{
public:
ListJobPrivate(const KUrl& url, bool _recursive, const QString &_prefix, bool _includeHidden)
ListJobPrivate(const KUrl& url, bool _recursive,
const QString &prefix, const QString &displayPrefix,
bool _includeHidden)
: SimpleJobPrivate(url, CMD_LISTDIR, QByteArray()),
recursive(_recursive), includeHidden(_includeHidden),
prefix(_prefix), m_processedEntries(0)
m_prefix(prefix), m_displayPrefix(displayPrefix), m_processedEntries(0)
{}
bool recursive;
bool includeHidden;
QString prefix;
QString m_prefix;
QString m_displayPrefix;
unsigned long m_processedEntries;
KUrl m_redirectionURL;
......@@ -2497,19 +2500,21 @@ public:
Q_DECLARE_PUBLIC(ListJob)
static inline ListJob *newJob(const KUrl& u, bool _recursive, const QString &_prefix,
static inline ListJob *newJob(const KUrl& u, bool _recursive,
const QString &prefix, const QString &displayPrefix,
bool _includeHidden, JobFlags flags = HideProgressInfo)
{
ListJob *job = new ListJob(*new ListJobPrivate(u, _recursive, _prefix, _includeHidden));
ListJob *job = new ListJob(*new ListJobPrivate(u, _recursive, prefix, displayPrefix, _includeHidden));
job->setUiDelegate(new JobUiDelegate);
if (!(flags & HideProgressInfo))
KIO::getJobTracker()->registerJob(job);
return job;
}
static inline ListJob *newJobNoUi(const KUrl& u, bool _recursive, const QString &_prefix,
static inline ListJob *newJobNoUi(const KUrl& u, bool _recursive,
const QString &prefix, const QString &displayPrefix,
bool _includeHidden)
{
return new ListJob(*new ListJobPrivate(u, _recursive, _prefix, _includeHidden));
return new ListJob(*new ListJobPrivate(u, _recursive, prefix, displayPrefix, _includeHidden));
}
};
......@@ -2558,11 +2563,15 @@ void ListJobPrivate::slotListEntries( const KIO::UDSEntryList& list )
if (entry.isDir() && !entry.isLink()) {
const QString filename = itemURL.fileName();
QString displayName = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
if (displayName.isEmpty())
displayName = filename;
// skip hidden dirs when listing if requested
if (filename != ".." && filename != "." && (includeHidden || filename[0] != '.')) {
ListJob *job = ListJobPrivate::newJobNoUi(itemURL,
true /*recursive*/,
prefix + filename + '/',
m_prefix + filename + '/',
m_displayPrefix + displayName + '/',
includeHidden);
Scheduler::setJobPriority(job, 1);
q->connect(job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
......@@ -2576,7 +2585,7 @@ void ListJobPrivate::slotListEntries( const KIO::UDSEntryList& list )
// Not recursive, or top-level of recursive listing : return now (send . and .. as well)
// exclusion of hidden files also requires the full sweep, but the case for full-listing
// a single dir is probably common enough to justify the shortcut
if (prefix.isNull() && includeHidden) {
if (m_prefix.isNull() && includeHidden) {
emit q->entries(q, list);
} else {
// cull the unwanted hidden dirs and/or parent dir references from the listing, then emit that
......@@ -2589,13 +2598,17 @@ void ListJobPrivate::slotListEntries( const KIO::UDSEntryList& list )
// Modify the name in the UDSEntry
UDSEntry newone = *it;
const QString filename = newone.stringValue( KIO::UDSEntry::UDS_NAME );
QString displayName = newone.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
if (displayName.isEmpty())
displayName = filename;
// Avoid returning entries like subdir/. and subdir/.., but include . and .. for
// the toplevel dir, and skip hidden files/dirs if that was requested
if ( (prefix.isNull() || (filename != ".." && filename != ".") )
if ( (m_prefix.isNull() || (filename != ".." && filename != ".") )
&& (includeHidden || (filename[0] != '.') ) )
{
// ## Didn't find a way to use the iterator instead of re-doing a key lookup
newone.insert( KIO::UDSEntry::UDS_NAME, prefix + filename );
newone.insert( KIO::UDSEntry::UDS_NAME, m_prefix + filename );
newone.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, m_displayPrefix + displayName);
newlist.append(newone);
}
}
......@@ -2684,12 +2697,12 @@ void ListJob::slotMetaData( const KIO::MetaData &_metaData)
ListJob *KIO::listDir( const KUrl& url, JobFlags flags, bool includeHidden )
{
return ListJobPrivate::newJob(url, false, QString(), includeHidden, flags);
return ListJobPrivate::newJob(url, false, QString(), QString(), includeHidden, flags);
}
ListJob *KIO::listRecursive( const KUrl& url, JobFlags flags, bool includeHidden )
{
return ListJobPrivate::newJob(url, true, QString(), includeHidden, flags);
return ListJobPrivate::newJob(url, true, QString(), QString(), includeHidden, flags);
}
void ListJob::setUnrestricted(bool unrestricted)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment