X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fdirectory_tree.cpp;h=dc78832fb64d13d977724ede7afabed1543c53ac;hb=e077c4de15dac0c54a37cef7ccb376e582c09ac8;hp=77ea9472c7f518e9a3bd4c161399971d209213f5;hpb=3ea085ec301ed1399dfa1e9f3a240312dc95410b;p=feisty_meow.git diff --git a/nucleus/library/filesystem/directory_tree.cpp b/nucleus/library/filesystem/directory_tree.cpp index 77ea9472..dc78832f 100644 --- a/nucleus/library/filesystem/directory_tree.cpp +++ b/nucleus/library/filesystem/directory_tree.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -28,16 +29,17 @@ #include using namespace basis; -using namespace structures; +using namespace loggers; using namespace nodes; +using namespace structures; using namespace textual; //#define DEBUG_DIRECTORY_TREE // uncomment for noisier version. #undef LOG -#define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s()) -//CLASS_EMERGENCY_LOG(program_wide_logger::get(), s) +#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()) ////////////// @@ -158,14 +160,12 @@ void directory_tree::text_form(astring &target, bool show_files) void directory_tree::traverse(const astring &path, const char *pattern, filename_tree &add_to) { -#ifdef DEBUG_DIRECTORY_TREE FUNCDEF("traverse"); -#endif // prepare the current node. add_to._dirname = filename(path, astring::empty_string()); add_to._files.reset(); #ifdef DEBUG_DIRECTORY_TREE - LOG(astring("working on node ") + add_to._dirname.raw()); + LOG(astring("working on node ") + add_to._dirname); #endif // open the directory. @@ -187,6 +187,12 @@ void directory_tree::traverse(const astring &path, const char *pattern, #ifdef DEBUG_DIRECTORY_TREE LOG(astring("seeking path: ") + new_path); #endif + if (!filename(new_path).is_normal()) { +//#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("bailing on weird dir: ") + new_path); +//#endif + continue; // only regular directories please. + } for (int q = 0; q < add_to.branches(); q++) { filename_tree *curr_kid = (filename_tree *)add_to.branch(q); #ifdef DEBUG_DIRECTORY_TREE @@ -260,9 +266,7 @@ dir_tree_iterator *directory_tree::start(traversal_types type) const bool directory_tree::jump_to(dir_tree_iterator &scanning, const astring &sub_path) { -#ifdef DEBUG_DIRECTORY_TREE FUNCDEF("jump_to"); -#endif string_array pieces; filename(sub_path).separate(pieces); for (int i = 0; i < pieces.length(); i++) { @@ -432,6 +436,12 @@ filename_tree *directory_tree::seek(const astring &dir_name_in, for (posn = 0; posn < examining.length(); posn++) { check = examining[posn]; filename current(check->_dirname); + if (!current.is_normal()) { +//#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("skipping abnormal dir: ") + current); +//#endif + continue; + } #ifdef DEBUG_DIRECTORY_TREE LOG(astring("looking at ") + current.raw()); #endif @@ -488,6 +498,13 @@ bool directory_tree::calculate(filename_tree *start, bool just_size) filename_list *files; // the filenames held at the iterator. while (directory_tree::current_dir(*ted, curr)) { + if (!curr.is_normal()) { +//#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("skipping abnormal dir: ") + curr); +//#endif + directory_tree::next(*ted); + continue; // scary non-simple file type. + } // we have a good directory to show. #ifdef DEBUG_DIRECTORY_TREE LOG(astring("calcing node ") + curr.raw()); @@ -495,6 +512,16 @@ bool directory_tree::calculate(filename_tree *start, bool just_size) files = directory_tree::access(*ted); directory_tree::depth(*ted, depth); for (int i = 0; i < files->elements(); i++) { + filename curr_file = curr + "/" + *files->borrow(i); +#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("got a curr file: ") + curr_file); +#endif + if (!curr_file.is_normal()) { +//#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("skipping abnormal file: ") + curr); +//#endif + continue; + } if (!files->borrow(i)->calculate(curr.raw(), just_size)) { LOG(astring("failure to calculate ") + files->get(i)->text_form()); } @@ -610,7 +637,6 @@ bool directory_tree::compare_trees(const directory_tree &source, if (!target_now // there was no node, so we're adding everything... || !target_now->_files.member_with_state(*files[i], how_compare) ) { // ... or we need to add this file since it's missing. - #ifdef DEBUG_DIRECTORY_TREE LOG(astring("adding record: ") + files[i]->text_form()); #endif @@ -668,9 +694,7 @@ outcome directory_tree::find_common_root(const astring &finding, bool exists, filename_tree * &found, astring &reassembled, string_array &pieces, int &match_place) { -#ifdef DEBUG_DIRECTORY_TREE FUNCDEF("find_common_root"); -#endif // test the path to find what it is. filename adding(finding); if (exists && !adding.good()) @@ -778,13 +802,19 @@ outcome directory_tree::add_path(const astring &new_item, bool just_size) filename adding(new_item); if (!adding.good()) { LOG(astring("non-existent new item! ") + new_item); + return common::NOT_FOUND; // not an existing path. + } + if (!adding.is_normal()) { +//#ifdef DEBUG_DIRECTORY_TREE + LOG(astring("abnormal new item: ") + new_item); +//#endif return common::BAD_INPUT; // not a good path. } int file_subtract = 0; // if it's a file, then we remove last component. if (!adding.is_directory()) file_subtract = 1; #ifdef DEBUG_DIRECTORY_TREE - if (file_subtract) LOG(astring("adding a file ") + new_item) - else LOG(astring("adding a directory ") + new_item); + if (file_subtract) { LOG(astring("adding a file ") + new_item); } + else { LOG(astring("adding a directory ") + new_item); } #endif // find the common root, break up the path into pieces, and tell us where @@ -874,9 +904,7 @@ outcome directory_tree::add_path(const astring &new_item, bool just_size) outcome directory_tree::remove_path(const astring &zap_item) { -#ifdef DEBUG_DIRECTORY_TREE FUNCDEF("remove_path"); -#endif // find the common root, if one exists. if not, we're not going to do this. string_array pieces; filename_tree *last_match = NIL;