Clone
ixen
committed
on 24 Dec 20
Fixed problem with file scan updating stats incorrectly (CH-371)
1.50beta1
/libchengine/TSubTaskScanDirectory.cpp (+1 -2)
118 118                 rFilesCache.Clear();
119 119
120 120                 bool bIgnoreDirs = GetTaskPropValue<eTO_IgnoreDirectories>(rConfig);
121 121                 bool bForceDirectories = GetTaskPropValue<eTO_CreateDirectoriesRelativeToRoot>(rConfig);
122 122                 bool bExcludeEmptyDirectories = GetTaskPropValue<eTO_ExcludeEmptyDirectories>(rConfig);
123 123
124 124                 // add everything
125 125                 TString strFormat;
126 126
127 127                 file_count_t fcSize = spBasePaths->GetCount();
128 128                 // NOTE: in theory, we should resume the scanning, but in practice we are always restarting scanning if interrupted.
129 129                 file_count_t fcIndex = 0;               // m_tSubTaskStats.GetCurrentIndex()
130 130                 for (; fcIndex < fcSize; fcIndex++)
131 131                 {
132 132                         TBasePathDataPtr spBasePath = spBasePaths->GetAt(fcIndex);
133 133                         TSmartPath pathCurrent = spBasePath->GetSrcPath();
134 134
135 135                         m_tSubTaskStats.SetCurrentIndex(fcIndex);
136 136
137 137                         // new stats
138                           m_tSubTaskStats.SetProcessedCount(fcIndex);
139 138                         m_tSubTaskStats.SetCurrentPath(pathCurrent.ToString());
140 139
141 140                         TFileInfoPtr spFileInfo(std::make_shared<TFileInfo>());
142 141
143 142                         // check if we want to process this path at all (might be already fast moved)
144 143                         if (spBasePath->GetSkipFurtherProcessing())
145 144                                 continue;
146 145
147 146                         // try to get some info about the input path; let user know if the path does not exist.
148 147                         ESubOperationResult eResult = tFilesystemFBWrapper.GetFileInfoFB(pathCurrent, spFileInfo, spBasePath);
149 148                         if (eResult == TSubTaskBase::eSubResult_SkipFile)
150 149                                 continue;
151 150                         if (eResult != TSubTaskBase::eSubResult_Continue)
152 151                                 return eResult;
153 152
154 153                         // log
155 154                         strFormat = _T("Adding file/folder (clipboard) : %path ...");
156 155                         strFormat.Replace(_T("%path"), pathCurrent.ToString());
157 156                         LOG_INFO(m_spLog) << strFormat.c_str();
158 157
 
192 191                         {
193 192                                 // add file info if passes filters
194 193                                 if (rafFilters.Match(spFileInfo))
195 194                                         rFilesCache.Add(spFileInfo);
196 195
197 196                                 // log
198 197                                 strFormat = _T("Added file %path");
199 198                                 strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString());
200 199                                 LOG_INFO(m_spLog) << strFormat.c_str();
201 200                         }
202 201                 }
203 202
204 203                 // update stats
205 204                 m_tSubTaskStats.SetCurrentIndex(fcIndex);
206 205
207 206                 auto totalCount = rFilesCache.GetCount();
208 207                 m_tSubTaskStats.SetTotalCount(totalCount);
209 208                 m_tSubTaskStats.SetProcessedCount(totalCount);
210 209                 auto totalSize = rFilesCache.CalculateTotalSize();
211 210                 m_tSubTaskStats.SetTotalSize(totalSize);
212                   m_tSubTaskStats.SetProcessedSize(0);
  211                 m_tSubTaskStats.SetProcessedSize(totalSize);
213 212
214 213                 m_tSubTaskStats.SetCurrentPath(TString());
215 214
216 215                 rFilesCache.SetComplete(true);
217 216
218 217                 // log
219 218                 LOG_INFO(m_spLog) << _T("Searching for files finished");
220 219
221 220                 return eSubResult_Continue;
222 221         }
223 222
224 223         void TSubTaskScanDirectories::GetStatsSnapshot(TSubTaskStatsSnapshotPtr& spStats) const
225 224         {
226 225                 m_tSubTaskStats.GetSnapshot(spStats);
227 226                 spStats->SetIgnoreSizeInAggregateStats(true);
228 227         }
229 228
230 229         size_t TSubTaskScanDirectories::ScanDirectory(TSmartPath pathDirName, const TBasePathDataPtr& spBasePathData,
231 230                 bool bIncludeDirs, const TFileFiltersArray& afFilters, bool bExcludeEmptyDirs)
232 231         {