FOR_EACH (node,nodes) { // Adding components std::list<std::shared_ptr<PlugNode>> node_and_components; PlugNodeUtils::node_and_components(*node, node_and_components); // Build nodes and components FOR_EACH (node_and_components_iter,node_and_components) { // Scan connections for (PlugIter p_iter(node_and_components_iter->get()); p_iter; ++p_iter) { if (p_iter()->is_no_draw()) continue; // Incoming if (p_iter()->has_incoming_connection()) { if (p_iter()->incoming_connection()->is_no_draw()) continue; cr.append_undo_command(CommandParams("ConnectPlugs \"" + p_iter()->incoming_connection()->full_name() + "\" \"" + p_iter()->full_name() + "\"" )); } // Outgoing const std::vector<PlugBase*> &connections = p_iter()->outgoing_connections(); for (DTuint k = 0; k < connections.size(); ++k) { if (connections[k]->is_no_draw()) continue; cr.append_undo_command(CommandParams("ConnectPlugs \"" + p_iter()->full_name() + "\" \"" + connections[k]->full_name() + "\"" )); } } // Events for (EventIter e_iter(node_and_components_iter->get()); e_iter; ++e_iter) { if (e_iter()->is_no_draw()) continue; // Incoming const std::vector<Event*> &connections_in = e_iter()->incoming_connections(); for (DTuint k = 0; k < connections_in.size(); ++k) { if (connections_in[k]->is_no_draw()) continue; cr.append_undo_command(CommandParams("ConnectEvents \"" + connections_in[k]->full_name() + "\" \"" + e_iter()->full_name() + "\"" )); } // Outgoing const std::vector<Event*> &connections_out = e_iter()->outgoing_connections(); for (DTuint k = 0; k < connections_out.size(); ++k) { if (connections_out[k]->is_no_draw()) continue; cr.append_undo_command(CommandParams("ConnectEvents \"" + e_iter()->full_name() + "\" \"" + connections_out[k]->full_name() + "\"" )); } } } }
void process_directory(const fs::path &directory, const long depth, ProcessParams ¶ms) { // Exclude entire directories bool exclude = false; std::vector<std::string>::const_iterator x_iter = params.excludes.begin(); std::vector<std::string>::const_iterator x_end = params.excludes.end(); for( ; x_iter != x_end; ++x_iter ) { if(boost::contains(directory.file_string(), *x_iter)) { exclude = true; break; } } if(exclude) { info(std::string("excluding directory: ") + directory.file_string() + " matched: " + *x_iter); ++params.dir_ex_count; return; } try { fs::directory_iterator p_iter(directory), p_end; for( ; p_iter != p_end; ++p_iter) { if( is_directory(*p_iter) ) { // recurse if we haven't hit the limit if(depth < params.limit_depth) process_directory(p_iter->path(), depth + 1, params); else { info(std::string("depth reached, skipping: ") + p_iter->path().file_string()); } } else if( is_regular_file(*p_iter) ) { // Check again for excluding file names exclude = false; x_iter = params.excludes.begin(); for( ; x_iter != x_end; ++x_iter ) { if(boost::contains(p_iter->path().file_string(), *x_iter)) { exclude = true; break; } } if(exclude) { info(std::string("excluding file: ") + p_iter->path().file_string() + " matched: " + *x_iter); ++params.file_ex_count; continue; } try { const fs::path dest_subdir = build_dest(*p_iter); fs::path dest_file; if(!dest_subdir.empty()) dest_file = params.dest_dir / dest_subdir; else if(params.ignore_unsorted) { info(std::string("ignoring unsorted: ") + p_iter->path().file_string()); ++params.unsorted_ignored_count; continue; } else { info(std::string("unsorted file (missing metadata): ") + p_iter->path().file_string()); dest_file = params.unsorted_dir; ++params.unsorted_count; } dest_file /= p_iter->filename(); if(fs::exists(dest_file)) { if(params.ignore_dups) { info(std::string("ignoring: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); ++params.dups_ignored_count; continue; } else { if(params.force) { info(std::string("force removing: ") + dest_file.file_string() + " for: " + p_iter->path().file_string()); if(!params.dry_run) fs::remove(dest_file); } else if(params.rename) { info(std::string("renaming: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); dest_file = uniquify(dest_file); } else { info(std::string("duplicate file: ") + p_iter->path().file_string() + " of: " + dest_file.file_string()); dest_file = params.dups_dir / dest_subdir / p_iter->filename(); // Ugh, more dup possibilities if(fs::exists(dest_file)) { info(std::string("renaming: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); dest_file = uniquify(dest_file); } } ++params.dups_count; } } if(!params.dry_run) fs::create_directories(dest_file.parent_path()); if(params.symlink) { info(std::string("linking from: ") + p_iter->path().file_string() + " to: " + dest_file.file_string()); if(!params.dry_run) { // The target of a symlink must be either absolute (aka complete) or // relative to the location of the link. Easiest solution is to make // a complete path. fs::path target; if(p_iter->path().is_complete()) target = p_iter->path(); else target = fs::initial_path() / p_iter->path(); fs::create_symlink(target, dest_file); } } else { info(std::string("copying from: ") + p_iter->path().file_string() + " to: " + dest_file.file_string()); if(!params.dry_run) { // Copy the file and restore its write time (needed for posix) std::time_t time = fs::last_write_time(*p_iter); fs::copy_file(*p_iter, dest_file); fs::last_write_time(dest_file, time); if(params.verify) { md5digest src_digest, dst_digest; bool ok = md5sum(p_iter->path(), src_digest); if(ok) ok = md5sum(dest_file, dst_digest); if(ok) ok = (memcmp(src_digest,dst_digest, sizeof(md5digest))==0); if(!ok) { // Should probably find a more appropriate exception for this throw std::runtime_error(std::string("File verification failed: '") + p_iter->path().file_string() + "' differs from '" + dest_file.file_string() + "'"); } else { info(std::string("verification passed")); } } } } if(params.move) { info(std::string("removing: ") + p_iter->path().file_string()); if(!params.dry_run) fs::remove(*p_iter); } if(!g_verbose && (params.ok_count % DOT_EVERY)==0) { std::cout << "." << std::flush; g_neednewline = true; } ++params.ok_count; } catch(fs::filesystem_error& e) { error(e, std::string("skipping file: " + p_iter->path().file_string())); ++params.file_err_count; } } } } catch(fs::filesystem_error& e) { error(e, std::string("skipping directory: " + directory.file_string())); ++params.dir_err_count; } }