#include #include #include #include #include #include #include "../shared/ThreadMonitor.h" #include "NfsHelper.h" namespace NfsHelper { // Pointer containing an error message std::unique_ptr strerror {new std::string}; std::string pathForFile(int64_t idNumber) { if (idNumber <= 0) return ""; // This should never happen. const int remainder = idNumber % DIVISOR; // The number 19 would go into bin 1 because 19 / 9 gives a remainer of 1. // So the path would be "layouts/9/1/19". Note that the divisor is part of // the path. Currently that's hard coded, but what if we need to change // that from 9 to 16 at some point? We probably don't want to recreate // this entire directory structure while the server is running. The new // path would be "layouts/16/3/19". We'd only use the new path for // writing. We'd possibly check both paths for reading or deleting. std::string result = "layouts/"; result += ntoa(DIVISOR); result += '/'; result += ntoa(remainder); result += '/'; result += ntoa(idNumber); return result; }; static const std::string s_saveToDisk = "saveToDisk"; TclList saveToDisk(int64_t channelId, std::string const &toSave) { ThreadMonitor::SetState tm(s_saveToDisk); tm.increment(s_saveToDisk); const std::string finalFileName = pathForFile(channelId); if (finalFileName.empty()) return TclList()<