MCPcopy Create free account
hub / github.com/amule-project/amule / ColdDiscoverSubdirs

Method ColdDiscoverSubdirs

src/SharedDirWatcher.cpp:405–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403
404
405void CSharedDirWatcher::ColdDiscoverSubdirs()
406{
407 if (!m_watcher) {
408 return;
409 }
410
411 thePrefs::PathList & shared = theApp->glob_prefs->shareddir_list;
412 if (shared.empty()) {
413 return;
414 }
415
416 // Walk only the user's recursive roots, not every shared dir.
417 // Non-recursive (explicit) shares are strict: their pre-existing
418 // subdirs do NOT get auto-included. Same policy as the HOT path
419 // (RegisterNewSubdirectory) -- both auto-add behaviours gate on
420 // IsRecursiveAncestor.
421 const thePrefs::PathList & roots =
422 theApp->glob_prefs->shareddir_recursive_list;
423 if (roots.empty()) {
424 return;
425 }
426
427 // Membership index over the current list: avoids O(N*M) string
428 // comparisons when M (newly-discovered subdirs) is large. Keys are
429 // raw path strings -- matches the comparison RegisterNewSubdirectory
430 // uses for its own dedup check, just lifted into a set.
431 // std::set rather than unordered_set: wxString has operator< but
432 // no stdlib std::hash specialization, and N here is at most a
433 // few thousand even on heavy users -- log-N membership is fine.
434 std::set<wxString> known;
435 for (size_t i = 0; i < shared.size(); ++i) {
436 known.insert(shared[i].GetRaw());
437 }
438
439 // Discovered new subdirs go here; we add them in bulk after the
440 // walk so a single SaveSharedFolders() flushes the whole batch
441 // rather than rewriting shareddir.dat once per discovery.
442 std::vector<CPath> discovered;
443
444 // Walk each recursive root's subtree. CSharedFileList's Reload
445 // already handled the root itself; this surfaces previously-
446 // uncovered descendants only.
447 for (size_t i = 0; i < roots.size(); ++i) {
448 const CPath & root = roots[i];
449 if (!root.IsOk() || !root.DirExists()) {
450 continue;
451 }
452 WalkForUnknownSubdirs(root, known, discovered);
453 }
454
455 if (discovered.empty()) {
456 return;
457 }
458
459 for (size_t i = 0; i < discovered.size(); ++i) {
460 const CPath & sub = discovered[i];
461 shared.push_back(sub);
462#ifndef __WXOSX__

Callers

nothing calls this directly

Calls 9

CFormatClass · 0.85
insertMethod · 0.80
GetRawMethod · 0.80
DirExistsMethod · 0.80
SaveSharedFoldersMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
IsOkMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected