/** * Recursively copy a file or directory. * @param src * Source file/directory to copy. * @param dst * Where to copy to. */ void copy_rec(const char *src, const char *dst) { /* Copy directory contents. */ DIR *dir = opendir(src); if (dir != NULL) { struct dirent *currentfile; char dir_src[HUGE_BUF], dir_dst[HUGE_BUF]; /* Try to make the new directory. */ if (access(dst, R_OK) != 0) { mkdir(dst, 0755); } while ((currentfile = readdir(dir))) { if (currentfile->d_name[0] == '.') { continue; } snprintf(dir_src, sizeof(dir_src), "%s/%s", src, currentfile->d_name); snprintf(dir_dst, sizeof(dir_dst), "%s/%s", dst, currentfile->d_name); copy_rec(dir_src, dir_dst); } closedir(dir); } else { copy_file(src, dst); } }
Tree::Tree(const Tree &t) : data(t.data) { dim = t.dim; // dimension rootbox = t.rootbox; // bounding box fulldepth = t.fulldepth; // depth of the tree root = new Node(0,0,0); // root of the tree top(); // set recursive vars copy_rec(root,t.root); }
/** * Copy a file/directory if it exists. * @param from * Directory where to copy from. * @param to * Directort to copy to. * @param src * File/directory to copy. * @param dst * Where to copy the file/directory to. */ void copy_if_exists(const char *from, const char *to, const char *src, const char *dst) { char src_path[HUGE_BUF], dst_path[HUGE_BUF]; snprintf(src_path, sizeof(src_path), "%s/%s", from, src); snprintf(dst_path, sizeof(dst_path), "%s/%s", to, dst); if (access(src_path, R_OK) == 0) { copy_rec(src_path, dst_path); } }
void Tree::copy_rec(Node *to, Node *from) { // printf("copying node %i (depth %i)\n",from->id,recdepth); if (recdepth == fulldepth) // at a leaf { data.set_node(to); // update entry for Node * } else if (from->children) // node has kids { for (int i=0; i<pow(2,dim); i++) { if (from->children[i]) { to->addchild(dim,i,from->children[i]->id); recdepth++; copy_rec(to->children[i], from->children[i]); recdepth--; } } } }