@@ -65,88 +65,116 @@ const QString UBFeaturesController::favoritePath = rootPath + "/Favorites";
6565const QString UBFeaturesController::webSearchPath = rootPath + " /Web search" ;
6666
6767
68- void UBFeaturesComputingThread::scanFS (const QUrl & currentPath, const QString & currVirtualPath, const QSet<QUrl> &pFavoriteSet )
68+ void UBFeaturesComputingThread::scanFS (const QUrl& currentPath, const QString& currVirtualPath, FeatureProcessor processFeature )
6969{
70- // Q_ASSERT(QFileInfo(currentPath.toLocalFile()).exists());
71- // if(QFileInfo(currentPath.toLocalFile()).exists())
72- // return;
70+ QSet<QString> scanRoots;
71+ scanRoots << currentPath.toLocalFile ();
7372
73+ scanFS (currentPath, currVirtualPath, scanRoots, processFeature);
74+ }
75+
76+ void UBFeaturesComputingThread::scanFS (const QUrl& currentPath, const QString& currVirtualPath, QSet<QString>& scanRoots, FeatureProcessor processFeature)
77+ {
7478 QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory (currentPath.toLocalFile ());
7579
76- QFileInfoList::iterator fileInfo;
77- for ( fileInfo = fileInfoList.begin (); fileInfo != fileInfoList.end (); fileInfo += 1 ) {
78- if (abort) {
80+ // new implementation taking care of symlinks
81+ for (const auto & fileInfo : fileInfoList)
82+ {
83+ if (abort)
84+ {
7985 return ;
8086 }
8187
82- QString fullFileName = fileInfo->absoluteFilePath ();
83- UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl (fullFileName);
84- QString fileName = fileInfo->fileName ();
85-
86- QImage icon = UBFeaturesController::getIcon (fullFileName, featureType);
87-
88- if ( fullFileName.contains (" .thumbnail." ))
89- continue ;
88+ if (fileInfo.isSymLink ())
89+ {
90+ const auto symLinkTarget = QFileInfo (fileInfo.symLinkTarget ());
9091
91- UBFeature testFeature (currVirtualPath + " /" + fileName, icon, fileName, QUrl::fromLocalFile (fullFileName), featureType);
92+ if (symLinkTarget.isDir ())
93+ {
94+ bool valid{true };
95+ // add trailing slash to make sure to compare full path segments afterwards
96+ const auto target = symLinkTarget.canonicalFilePath () + " /" ;
97+
98+ // check target
99+ for (const auto & root : scanRoots)
100+ {
101+ if (root.startsWith (target) || target.startsWith (root))
102+ {
103+ qDebug () << " skipping" << fileInfo << " linking to" << target;
104+ valid = false ;
105+ break ;
106+ }
107+ }
108+
109+ if (!valid)
110+ {
111+ continue ;
112+ }
113+
114+ scanRoots << target;
115+ }
116+ }
92117
93- emit sendFeature (testFeature);
94- emit featureSent ();
95- emit scanPath (fullFileName);
118+ const auto fullFileName = fileInfo.canonicalFilePath ();
119+ const auto featureType = UBFeaturesController::fileTypeFromUrl (fullFileName);
96120
97- if ( pFavoriteSet. find ( QUrl::fromLocalFile (fullFileName)) != pFavoriteSet. end ()) {
98- // TODO send favoritePath from the controller or make favoritePath public and static
99- emit sendFeature ( UBFeature ( UBFeaturesController::favoritePath + " / " + fileName, icon, fileName, QUrl::fromLocalFile (fullFileName), featureType)) ;
121+ if (featureType == UBFeatureElementType:: FEATURE_INVALID || fullFileName. contains ( " .thumbnail. " ))
122+ {
123+ continue ;
100124 }
101125
102- if (featureType == FEATURE_FOLDER ) {
103- scanFS (QUrl::fromLocalFile (fullFileName), currVirtualPath + " /" + fileName, pFavoriteSet);
126+ processFeature (fileInfo, featureType, currVirtualPath);
127+
128+ if (featureType == UBFeatureElementType::FEATURE_FOLDER )
129+ {
130+ // scan recursive
131+ scanFS (QUrl::fromLocalFile (fullFileName), currVirtualPath + " /" + fileInfo.fileName (), scanRoots, processFeature);
104132 }
105133 }
106134}
107135
108136void UBFeaturesComputingThread::scanAll (QList<QPair<QUrl, UBFeature> > pScanningData, const QSet<QUrl> &pFavoriteSet)
109137{
110- for (int i = 0 ; i < pScanningData.count (); i++) {
138+ for (const auto curPair : pScanningData)
139+ {
111140 if (abort) {
112141 return ;
113142 }
114- QPair<QUrl, UBFeature> curPair = pScanningData.at (i);
115143
116144 emit scanCategory (curPair.second .getDisplayName ());
117- scanFS (curPair.first , curPair.second .getFullVirtualPath (), pFavoriteSet);
118- }
119- }
120145
121- int UBFeaturesComputingThread::featuresCount (const QUrl &pPath)
122- {
123- int noItems = 0 ;
146+ const auto currVirtualPath = curPair.second .getFullVirtualPath ();
124147
125- QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory (pPath.toLocalFile ());
148+ scanFS (curPair.first , currVirtualPath, [this , &pFavoriteSet](const QFileInfo& fileInfo, UBFeatureElementType featureType, QString virtualPath){
149+ const auto fileName = fileInfo.fileName ();
150+ const auto fullFileName = fileInfo.canonicalFilePath ();
151+ QImage icon = UBFeaturesController::getIcon (fullFileName, featureType);
126152
127- QFileInfoList::iterator fileInfo;
128- for ( fileInfo = fileInfoList.begin (); fileInfo != fileInfoList.end (); fileInfo += 1 ) {
129- QString fullFileName = fileInfo->absoluteFilePath ();
130- UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl (fullFileName);
153+ UBFeature testFeature{virtualPath + " /" + fileName, icon, fileName, QUrl::fromLocalFile (fullFileName), featureType};
131154
132- if (featureType != FEATURE_INVALID && !fullFileName. contains ( " .thumbnail. " )) {
133- noItems++ ;
134- }
155+ emit sendFeature (testFeature);
156+ emit featureSent () ;
157+ emit scanPath (fullFileName);
135158
136- if (featureType == FEATURE_FOLDER ) {
137- noItems += featuresCount (QUrl::fromLocalFile (fullFileName));
138- }
159+ if (pFavoriteSet.contains (QUrl::fromLocalFile (fullFileName)))
160+ {
161+ emit sendFeature (UBFeature{UBFeaturesController::favoritePath + " /" + fileName, icon, fileName, QUrl::fromLocalFile (fullFileName), featureType});
162+ }
163+ });
139164 }
140-
141- return noItems;
142165}
143166
144167int UBFeaturesComputingThread::featuresCountAll (QList<QPair<QUrl, UBFeature> > pScanningData)
145168{
146169 int noItems = 0 ;
147- for (int i = 0 ; i < pScanningData.count (); i++) {
148- QPair<QUrl, UBFeature> curPair = pScanningData.at (i);
149- noItems += featuresCount (curPair.first );
170+
171+ for (const auto curPair : pScanningData)
172+ {
173+ const auto currVirtualPath = curPair.second .getFullVirtualPath ();
174+
175+ scanFS (curPair.first , currVirtualPath, [this , &noItems](const QFileInfo& fileInfo, UBFeatureElementType featureType, QString virtualPath){
176+ ++noItems;
177+ });
150178 }
151179
152180 return noItems;
@@ -452,60 +480,6 @@ void UBFeaturesController::scanFS()
452480 }
453481}
454482
455- void UBFeaturesController::fileSystemScan (const QUrl & currentPath, const QString & currVirtualPath)
456- {
457- QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory (currentPath.toLocalFile ());
458-
459- QFileInfoList::iterator fileInfo;
460- for ( fileInfo = fileInfoList.begin (); fileInfo != fileInfoList.end (); fileInfo += 1 ) {
461- QString fullFileName = fileInfo->absoluteFilePath ();
462- UBFeatureElementType featureType = fileTypeFromUrl (fullFileName);
463- QString fileName = fileInfo->fileName ();
464-
465- QImage icon = getIcon (fullFileName, featureType);
466-
467- if ( fullFileName.contains (" .thumbnail." ))
468- continue ;
469-
470- UBFeature testFeature (currVirtualPath + " /" + fileName, icon, fileName, QUrl::fromLocalFile (fullFileName), featureType);
471-
472- featuresList->append (testFeature);
473-
474- if ( favoriteSet->find ( QUrl::fromLocalFile ( fullFileName ) ) != favoriteSet->end () ) {
475- featuresList->append ( UBFeature ( favoritePath + " /" + fileName, icon, fileName, QUrl::fromLocalFile ( fullFileName ), featureType ) );
476- }
477-
478- if (featureType == FEATURE_FOLDER ) {
479- fileSystemScan (QUrl::fromLocalFile (fullFileName), currVirtualPath + " /" + fileName);
480- }
481- }
482- }
483-
484- int UBFeaturesController::featuresCount (const QUrl &currPath)
485- {
486- int noItems = 0 ;
487-
488- QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory (currPath.toLocalFile ());
489-
490- QFileInfoList::iterator fileInfo;
491- for ( fileInfo = fileInfoList.begin (); fileInfo != fileInfoList.end (); fileInfo += 1 ) {
492- QString fullFileName = fileInfo->absoluteFilePath ();
493- UBFeatureElementType featureType = fileTypeFromUrl (fullFileName);
494-
495- if (featureType != FEATURE_INVALID && !fullFileName.contains (" .thumbnail." )) {
496- noItems++;
497- } else {
498- continue ;
499- }
500-
501- if (featureType == FEATURE_FOLDER ) {
502- noItems += featuresCount (QUrl::fromLocalFile (fullFileName));
503- }
504- }
505-
506- return noItems;
507- }
508-
509483bool UBFeaturesController::isInFavoriteList (QUrl url)
510484{
511485 return favoriteSet->contains (url);
0 commit comments