X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fheavy_file_ops.cpp;h=9a5451b74687355869bcf82de5e0803efc703423;hb=80118cc1248b9569821aa245f900cf028a57f9f4;hp=3ddd76648930cee349a1d8f2b6dd467bd19ca7af;hpb=0fa7b30df320a093cd6ac3b0231652e3322058d2;p=feisty_meow.git diff --git a/nucleus/library/filesystem/heavy_file_ops.cpp b/nucleus/library/filesystem/heavy_file_ops.cpp index 3ddd7664..9a5451b7 100644 --- a/nucleus/library/filesystem/heavy_file_ops.cpp +++ b/nucleus/library/filesystem/heavy_file_ops.cpp @@ -27,16 +27,17 @@ using namespace structures; namespace filesystem { -#define DEBUG_HEAVY_FILE_OPS +//#define DEBUG_HEAVY_FILE_OPS // uncomment for noisier debugging. #undef LOG -#ifdef DEBUG_HEAVY_FILE_OPS - #include - #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s()) -#else - #define LOG(s) {if(!!s){}} -#endif +#include +#define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s()) + +////////////// + +// the smallest we let the packing area's available space get before we stop filling it. +const int MINIMUM_ARRAY_SIZE = 1024; ////////////// @@ -167,14 +168,18 @@ outcome heavy_file_operations::write_file_chunk(const astring &target, double byte_start, const byte_array &chunk, bool truncate, int copy_chunk_factor) { -#ifdef DEBUG_HEAVY_FILE_OPS -// FUNCDEF("write_file_chunk"); -#endif + FUNCDEF("write_file_chunk"); if (byte_start < 0) return BAD_INPUT; filename targ_name(target); - if (!directory::recursive_create(targ_name.dirname().raw())) + astring targ_dir = targ_name.dirname().raw(); +#ifdef DEBUG_HEAVY_FILE_OPS + LOG(astring("creating target's directory: ") + targ_name.dirname().raw()); +#endif + if (!directory::recursive_create(targ_dir)) { + LOG(astring("failed to create directory: ") + targ_name.dirname().raw()); return TARGET_DIR_ERROR; + } if (!targ_name.exists()) { huge_file target_file(target, "w"); @@ -247,7 +252,7 @@ outcome heavy_file_operations::buffer_files(const astring &source_root, while (storage.length() < maximum_bytes) { double remaining_in_array = maximum_bytes - storage.length() - last_action.packed_size(); - if (remaining_in_array < 128) { + if (remaining_in_array < MINIMUM_ARRAY_SIZE) { // ensure that we at least have a reasonable amount of space left // for storing into the array. break; @@ -273,15 +278,17 @@ outcome heavy_file_operations::buffer_files(const astring &source_root, huge_file current(full_file, "rb"); if (!current.good()) { // we need to skip this file. -LOG(astring("skipping bad file: ") + full_file); + LOG(astring("skipping bad file: ") + full_file); to_return = advance(to_transfer, last_action); if (to_return != OKAY) break; continue; } if (last_action._byte_start + last_action._length >= current.length()) { -LOG(astring("finished stuffing file: ") + full_file); // this file is done now. go to the next one. +#ifdef DEBUG_HEAVY_FILE_OPS + LOG(astring("finished stuffing file: ") + full_file); +#endif to_return = advance(to_transfer, last_action); if (to_return != OKAY) break; continue;