Clone
ixen
committed
on 24 Aug 22
Fix handling of network paths by adding \\?\UNC\ prefix instead of \\?\ (CH-374)
src/libchengine/TLocalFilesystem.cpp (+16 -5)
324 324                 }
325 325
326 326                 LOG_DEBUG(m_spLog) << L"Successfully fast-moved file " << pathMoveFrom << L" to " << pathMoveTo;
327 327         }
328 328
329 329         IFilesystemFindPtr TLocalFilesystem::CreateFinderObject(const TSmartPath& pathDir, const TSmartPath& pathMask)
330 330         {
331 331                 LOG_TRACE(m_spLog) << L"Creating file finder object for path " << pathDir << L" with mask " << pathMask;
332 332
333 333                 return std::shared_ptr<TLocalFilesystemFind>(new TLocalFilesystemFind(pathDir, pathMask, m_spLog->GetLogFileData()));
334 334         }
335 335
336 336         IFilesystemFilePtr TLocalFilesystem::CreateFileObject(IFilesystemFile::EOpenMode eMode, const TSmartPath& pathFile, bool bNoBuffering, bool bProtectReadOnlyFiles)
337 337         {
338 338                 LOG_TRACE(m_spLog) << L"Creating file object for path " << pathFile << L" with no-buffering set to " << bNoBuffering << L" and protect-read-only set to " << bProtectReadOnlyFiles;
339 339                 return std::shared_ptr<TLocalFilesystemFile>(new TLocalFilesystemFile(eMode, pathFile, bNoBuffering, bProtectReadOnlyFiles, m_spLog->GetLogFileData()));
340 340         }
341 341
342 342         TSmartPath TLocalFilesystem::PrependPathExtensionIfNeeded(const TSmartPath& pathInput)
343 343         {
  344                 if(pathInput.IsNetworkPath())
  345                 {
  346                         const TSmartPath pathNetPrefix = PathFromString(L"\\\\?\\UNC\\");
  347                         if(!pathInput.StartsWith(pathNetPrefix))
  348                                 return pathNetPrefix + PathFromWString(pathInput.ToWString().Mid(1));
  349                 }
  350                 else
  351                 {
344 352                         const TSmartPath pathPrefix = PathFromString(L"\\\\?\\");
345  
346 353                         if(!pathInput.StartsWith(pathPrefix))
347 354                                 return pathPrefix + pathInput;
  355                 }
348 356
349 357                 return pathInput;
350 358         }
351 359
352 360         TSmartPath TLocalFilesystem::StripPathExtensionIfNeeded(const TSmartPath& pathInput)
353 361         {
354 362                 const TSmartPath pathPrefix = PathFromString(L"\\\\?\\");
  363                 const TSmartPath pathNetPrefix = PathFromString(L"\\\\?\\UNC\\");
355 364
356                   if(pathInput.StartsWith(pathPrefix))
  365                 if(pathInput.StartsWith(pathNetPrefix))
  366                         return PathFromString(pathInput.ToWString().Mid(pathNetPrefix.GetLength()).c_str());
  367                 else if(pathInput.StartsWith(pathPrefix))
357 368                         return PathFromString(pathInput.ToWString().Mid(pathPrefix.GetLength()).c_str());
358 369
359 370                 return pathInput;
360 371         }
361 372
362 373         TLocalFilesystem::EPathsRelation TLocalFilesystem::GetPathsRelation(const TSmartPath& pathFirst, const TSmartPath& pathSecond)
363 374         {
364 375                 if (pathFirst.IsEmpty())
365 376                         throw TCoreException(eErr_InvalidArgument, L"pathFirst", LOCATION);
366 377                 if(pathSecond.IsEmpty())
367 378                         throw TCoreException(eErr_InvalidArgument, L"pathSecond", LOCATION);
368 379
369 380                 LOG_DEBUG(m_spLog) << L"Trying to find relation between paths: " << pathFirst << L" and " << pathSecond;
370 381
371 382                 // get information about both paths
372 383                 UINT uiFirstDriveType = GetDriveData(pathFirst);
373 384                 UINT uiSecondDriveType = GetDriveData(pathSecond);
374 385
375 386                 LOG_TRACE(m_spLog) << L"Drive type for " << pathFirst << L" is " << uiFirstDriveType << L", drive type for " << pathSecond << L" is " << uiSecondDriveType;
376 387