X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fdirectory_tree.cpp;h=54a8ca9bcf2c684337b87f83fedda460794314dc;hb=46db3e069f6346301f8d55a1d155a4904f18ec1e;hp=68b82b7fc7d3cdbf41e27182acf178596f6a0d86;hpb=51d71c226be424b6a698c7474d237e8c69661af5;p=feisty_meow.git diff --git a/nucleus/library/filesystem/directory_tree.cpp b/nucleus/library/filesystem/directory_tree.cpp index 68b82b7f..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, "*"); @@ -274,7 +275,8 @@ bool directory_tree::jump_to(dir_tree_iterator &scanning, { FUNCDEF("jump_to"); string_array pieces; - filename(sub_path).separate(pieces); + bool rooted; + filename(sub_path).separate(rooted, pieces); for (int i = 0; i < pieces.length(); i++) { filename_tree *curr = dynamic_cast(scanning.current()); #ifdef DEBUG_DIRECTORY_TREE @@ -282,7 +284,7 @@ bool directory_tree::jump_to(dir_tree_iterator &scanning, #endif string_array sub_pieces = pieces.subarray(i, i); filename curr_path; - curr_path.join(sub_pieces); + curr_path.join(rooted, sub_pieces); curr_path = filename(curr->_dirname.raw() + filename::default_separator() + curr_path.raw()); #ifdef DEBUG_DIRECTORY_TREE @@ -444,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; } @@ -494,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 @@ -506,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. @@ -583,7 +588,8 @@ bool directory_tree::compare_trees(const directory_tree &source, int source_pieces = 0; { string_array temp; - filename(real_source_start).separate(temp); + bool rooted_source; + filename(real_source_start).separate(rooted_source, temp); source_pieces = temp.length(); } @@ -597,7 +603,8 @@ bool directory_tree::compare_trees(const directory_tree &source, #endif string_array pieces; - curr.separate(pieces); // get the components of the current location. + bool curr_rooted; + curr.separate(curr_rooted, pieces); // get the components of the current location. #ifdef DEBUG_DIRECTORY_TREE LOG(astring("name in pieces:") + pieces.text_form()); #endif @@ -605,7 +612,8 @@ bool directory_tree::compare_trees(const directory_tree &source, // snap the root components out of there. filename corresponding_name; - corresponding_name.join(pieces); +//hmmm: is that right decision? + corresponding_name.join(false, pieces); #ifdef DEBUG_DIRECTORY_TREE LOG(astring("computed target name as: ") + corresponding_name); #endif @@ -637,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. @@ -715,13 +723,15 @@ outcome directory_tree::find_common_root(const astring &finding, bool exists, // break up the path into pieces. pieces.reset(); - adding.separate(pieces); + bool rooted; + adding.separate(rooted, pieces); // break up our root into pieces; we must take off components that are // already in the root. string_array root_pieces; + bool root_rooted; filename temp_file(path()); - temp_file.separate(root_pieces); + temp_file.separate(root_rooted, root_pieces); // locate the last place where the path we were given touches our tree. // it could be totally new, partially new, or already contained. @@ -866,7 +876,8 @@ outcome directory_tree::add_path(const astring &new_item, bool just_size) #endif // handle the case for files now that we have our proper node. string_array partial_pieces; - filename(reassembled).separate(partial_pieces); + bool partial_rooted; + filename(reassembled).separate(partial_rooted, partial_pieces); int levels_missing = pieces.length() - partial_pieces.length(); // we loop over all the pieces that were missing in between the last @@ -982,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.