void OutputFileHandler::CommonConstructor(const std::string& rDirectory, bool cleanOutputDirectory) { // Is it a valid request for a directory? if (rDirectory.find("..") != std::string::npos) { EXCEPTION("Will not create directory: " + rDirectory + " due to it potentially being above, and cleaning, CHASTE_TEST_OUTPUT."); // Note: in Boost 1.48 and above we could use 'canonical' to check this better } //The notion of absolute path on Windows is rather different. //For example, / and /foo are not absolute paths. //However, fs::path.has_root_path() captures the intended semantics here as follows if (fs::path(rDirectory).has_root_path()) { EXCEPTION("The constructor argument to OutputFileHandler must be a relative path; '" << rDirectory << "' is absolute."); } mDirectory = MakeFoldersAndReturnFullPath(rDirectory); // Clean the directory (default) if (rDirectory != "" && cleanOutputDirectory) // Clean directory but don't ever clean CHASTE_TEST_OUTPUT at the top level { FileFinder signature_file(mDirectory + SIG_FILE_NAME, RelativeTo::Absolute); if (!signature_file.Exists()) { EXCEPTION("Cannot delete " + mDirectory + " because signature file \"" + SIG_FILE_NAME + "\" is not present."); } // Are we the master process? Only the master should delete files if (PetscTools::AmMaster()) { CleanFolder(mDirectory); } // Wait for master to finish before going on to use the directory. PetscTools::Barrier("OutputFileHandler"); } }
static PyObject * sherlock_signature(PyObject *self, PyObject *args) { int i; const char *filepath; Sig *ret_sig; if (!PyArg_ParseTuple(args, "s", &filepath)) return NULL; ret_sig = signature_file(filepath); PyObject* list = PyList_New(0); for (i = 0; i < ret_sig->nval; i++) { static char sigbuf[MAX_HASH_BUFFER_SIZE]; snprintf(sigbuf, MAX_HASH_BUFFER_SIZE, "%lx", ret_sig->val[i]); PyObject *val = Py_BuildValue("s", sigbuf); PyList_Append(list, val); } return list; }