X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fdirectory_tree.cpp;h=54a8ca9bcf2c684337b87f83fedda460794314dc;hb=46db3e069f6346301f8d55a1d155a4904f18ec1e;hp=bf554db17b3f289210780fd387c9a342ab5e9193;hpb=1d0e3f784ca8c86185013026e8500f8460aefe8e;p=feisty_meow.git diff --git a/nucleus/library/filesystem/directory_tree.cpp b/nucleus/library/filesystem/directory_tree.cpp index bf554db1..54a8ca9b 100644 --- a/nucleus/library/filesystem/directory_tree.cpp +++ b/nucleus/library/filesystem/directory_tree.cpp @@ -34,12 +34,11 @@ using namespace nodes; using namespace structures; using namespace textual; -#define DEBUG_DIRECTORY_TREE +//#define DEBUG_DIRECTORY_TREE // uncomment for noisier version. #undef LOG #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), to_print) -//printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s()) ////////////// @@ -234,7 +233,9 @@ bool directory_tree::reset(const astring &path, const char *pattern) *_pattern = pattern; _real_tree = new filename_tree; -LOG(astring("dirtree::reset to path: ") + path); +#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("dirtree::reset to path: ") + path); +#endif // check that the top-level is healthy. directory curr(path, "*"); @@ -445,7 +446,7 @@ filename_tree *directory_tree::seek(const astring &dir_name_in, filename current(check->_dirname); if (!current.is_normal()) { //#ifdef DEBUG_DIRECTORY_TREE - LOG(astring("skipping abnormal dir: \"") + current + "\""); + LOG(astring("seek: skipping abnormal dir: \"") + current + "\""); //#endif continue; } @@ -495,6 +496,9 @@ bool directory_tree::calculate(bool just_size) bool directory_tree::calculate(filename_tree *start, bool just_size) { FUNCDEF("calculate"); +#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("calculate: got tree to start with at ") + start->_dirname.raw()); +#endif dir_tree_iterator *ted = start_at(start, directory_tree::postfix); // create our iterator to do a postfix traversal. why postfix? well, // prefix has been used elsewhere and since it doesn't really matter what @@ -507,7 +511,7 @@ bool directory_tree::calculate(filename_tree *start, bool just_size) while (directory_tree::current_dir(*ted, curr)) { if (!curr.is_normal()) { //#ifdef DEBUG_DIRECTORY_TREE - LOG(astring("skipping abnormal dir: \"") + curr + "\""); + LOG(astring("calculate: skipping abnormal dir: \"") + curr + "\""); //#endif directory_tree::next(*ted); continue; // scary non-simple file type. @@ -641,10 +645,10 @@ bool directory_tree::compare_trees(const directory_tree &source, if (!target_now) { // that entire sub-tree is missing. add all of the files here into // the list. -#ifdef DEBUG_DIRECTORY_TREE +//#ifdef DEBUG_DIRECTORY_TREE LOG(astring("could not find dir in target for ") + curr.raw() + " which we computed corresp as " + corresponding_name.raw()); -#endif +//#endif } // now scan across all the files that are in our source list. @@ -989,6 +993,46 @@ outcome directory_tree::remove_path(const astring &zap_item) return common::OKAY; } -} //namespace. +basis::outcome directory_tree::make_directories(const basis::astring new_root) +{ + FUNCDEF("make_directories"); + // iterate down the tree, making all the directories requested. + dir_tree_iterator *ted = start(directory_tree::prefix); + + int depth; // current depth in tree. + filename curr; // the current path the iterator is at. + string_array files; // the filenames held at the iterator. + +#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("new root is ") + new_root); +#endif + filename old_root = path(); +#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("old root was ") + old_root.raw()); +#endif + while (current(*ted, curr, files)) { + // we have a good directory to show. + directory_tree::depth(*ted, depth); + int found = curr.find(old_root); + if (found < common::OKAY) { + LOG(astring("failed to find prefix of path '") + old_root + + "' in the current directory '" + curr + "'"); + return found; + } + curr = curr.substring(found + old_root.length(), curr.end()); +//LOG(astring("curr now is: ") + curr); + filename dir_to_make(new_root + "/" + curr); +#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("creating dir: ") + dir_to_make.raw()); +#endif + directory::recursive_create(dir_to_make.raw()); + next(*ted); + } + + throw_out(ted); + return common::OKAY; +} + +} //namespace.