2424
2525#include " util/cxx17retrocompat.h"
2626#include " util/folderiterator.h"
27- #include < algorithm>
2827#include " util/rstime.h"
2928#include " rsserver/p3face.h"
3029#include " directory_storage.h"
@@ -221,9 +220,11 @@ bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready)
221220 RS_DBG4 (" recursing into \" " , stored_dir_it.name ());
222221
223222 std::string canonical = RsDirUtil::removeSymLinks (stored_dir_it.name ());
224- existing_dirs.insert (canonical);
225- std::vector<std::string> current_branch_real_paths;
226- current_branch_real_paths.push_back (canonical);
223+ if (!canonical.empty ())
224+ existing_dirs.insert (canonical);
225+ std::set<std::string> current_branch_real_paths;
226+ if (!canonical.empty ())
227+ current_branch_real_paths.insert (canonical);
227228 recursUpdateSharedDir (
228229 stored_dir_it.name (), *stored_dir_it,
229230 existing_dirs, current_branch_real_paths, 1 , some_files_not_ready );
@@ -244,7 +245,7 @@ bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready)
244245
245246void LocalDirectoryUpdater::recursUpdateSharedDir (
246247 const std::string& cumulated_path, DirectoryStorage::EntryIndex indx,
247- std::set<std::string>& existing_directories, std::vector <std::string>& current_branch_real_paths, uint32_t current_depth,
248+ std::set<std::string>& existing_directories, std::set <std::string>& current_branch_real_paths, uint32_t current_depth,
248249 bool & some_files_not_ready )
249250{
250251 RS_DBG4 (" parsing directory \" " , cumulated_path, " \" index: " , indx);
@@ -309,7 +310,13 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(
309310 std::string real_path = RsDirUtil::removeSymLinks (
310311 RsDirUtil::makePath (cumulated_path, dirIt.file_name ()) );
311312
312- if (std::find (current_branch_real_paths.begin (), current_branch_real_paths.end (), real_path) != current_branch_real_paths.end ())
313+ if (real_path.empty ())
314+ {
315+ RS_WARN ( " Broken/circular symlink: \" " , cumulated_path,
316+ " /" , dirIt.file_name (), " \" . Ignoring." );
317+ dir_is_accepted = false ;
318+ }
319+ else if (current_branch_real_paths.end () != current_branch_real_paths.find (real_path))
313320 {
314321 RS_WARN ( " Circular symlink detected: \" " , cumulated_path,
315322 " \" points to ancestor \" " , real_path,
@@ -381,13 +388,15 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(
381388 {
382389 std::string next_path = RsDirUtil::makePath (cumulated_path, stored_dir_it.name ());
383390 std::string canonical = RsDirUtil::removeSymLinks (next_path);
384- current_branch_real_paths.push_back (canonical);
391+ if (!canonical.empty ())
392+ current_branch_real_paths.insert (canonical);
385393
386394 recursUpdateSharedDir ( next_path,
387395 *stored_dir_it, existing_directories, current_branch_real_paths,
388396 current_depth+1 , some_files_not_ready );
389397
390- current_branch_real_paths.pop_back ();
398+ if (!canonical.empty ())
399+ current_branch_real_paths.erase (canonical);
391400 }
392401}
393402
0 commit comments