void FastOS_FileInterface::EmptyDirectory( const char *dir, const char *keepFile /* = nullptr */ ) { FastOS_StatInfo statInfo; if (!FastOS_File::Stat(dir, &statInfo)) return; // Fail if the directory does not exist FastOS_DirectoryScan dirScan( dir ); while (dirScan.ReadNext()) { if (strcmp(dirScan.GetName(), ".") != 0 && strcmp(dirScan.GetName(), "..") != 0 && (keepFile == nullptr || strcmp(dirScan.GetName(), keepFile) != 0)) { std::string name = dir; name += GetPathSeparator(); name += dirScan.GetName(); if (dirScan.IsDirectory()) { EmptyAndRemoveDirectory(name.c_str()); } else { if ( ! FastOS_File::Delete(name.c_str()) ) { std::ostringstream os; os << "Failed deleting file '" << name << "' due to " << getLastErrorString(); throw std::runtime_error(os.str().c_str()); } } } } }
bool rename(const path & old_p, const path & new_p, bool overwrite) { DWORD flags = overwrite ? MOVEFILE_REPLACE_EXISTING : 0; bool ret = MoveFileExA(old_p.string().c_str(), new_p.string().c_str(), flags) == TRUE; if(!ret) { LogWarning << "MoveFileExA(" << old_p << ", " << new_p << ", " << flags << ") failed! " << getLastErrorString(); } return ret; }
bool remove(const path & p) { bool succeeded = true; if(is_directory(p)) { succeeded &= RemoveDirectoryA(p.string().c_str()) == TRUE; if(!succeeded) { LogWarning << "RemoveDirectoryA(" << p << ") failed! " << getLastErrorString(); } } else { succeeded &= DeleteFileA(p.string().c_str()) == TRUE; if(!succeeded) { LogWarning << "DeleteFileA(" << p << ") failed! " << getLastErrorString(); } } return succeeded; }
bool create_directory(const path & p) { if(p.empty()) { return true; } bool ret = CreateDirectoryA(p.string().c_str(), NULL) == TRUE; if(!ret) { int lastError = GetLastError(); ret = lastError == ERROR_ALREADY_EXISTS; if(!ret) { LogWarning << "CreateDirectoryA(" << p << ", NULL) failed! " << getLastErrorString(); } } return ret; }
//----[ doPathing ]---------------------------------------------------------- bool Pather::doPathing(const SliceStack& slices, PatherProgressCallback* callback) { const SliceArray& slice_array = slices.getSlices(); // Let the callback know how many slices are going to be computed if (callback) callback->setNumberOfSlices(slice_array.size()); for (int i = 0; i < slice_array.size(); i++) { // Start building a new slice PathSlice* current_slice = new PathSlice(slice_array[i].getZ()); // Put the paths for all of the materials into the slice const SliceMaterialArray& material_array = slice_array[i].getMaterials(); for (int j = 0; j < material_array.size(); j++) { // Build this material PathSliceMaterial* current_material = new PathSliceMaterial(material_array[j].getMaterialID()); // For each of the different regions this material contains in this // layer, add all of the paths that are needed to cover that region. const SliceMaterialRegionArray& regions = material_array[j].getRegions(); for (int k = 0; k < regions.size(); ++k) { PathSliceRegion* current_region = new PathSliceRegion(); if (!runPathingAlgorithm(regions[k], current_region, callback)) { if (callback) callback->encounteredIssue(getLastErrorString()); return false; } current_material->add(current_region); } current_slice->addMaterial(current_material); } path_stack_.addSlice(current_slice); if (callback) callback->sliceHasBeenComputed(i, current_slice); } // successs! return true; }
END_TEST //Nothing wrong, should work! START_TEST (simple_uncompressed_dta) { const char* filename="/tmp/check_lbadta_simple_uncompressed_dta"; FILE *fileptr = fopen(filename, "wb"); uint32_t headersize = 8; fwrite(&headersize, 4, 1, fileptr); uint32_t headerentry = 8; fwrite(&headerentry, 4, 1, fileptr); uint32_t uncompsize = 4; fwrite(&uncompsize, 4, 1, fileptr); uint32_t compsize = 4; fwrite(&compsize, 4, 1, fileptr); uint16_t mode = 0; fwrite(&mode, 2, 1, fileptr); uint32_t data = 0x12345678; fwrite(&data, 4, 1, fileptr); fclose(fileptr); fileptr = fopen(filename, "rb"); long int streampos = ftell(fileptr); struct HQREntry entry; hqr_getItemInformation(&errmem, fileptr, 1, &entry); printf("%d\n", entry.offset); printf("%d\n", entry.uncompressed_size); fail_unless(entry.uncompressed_size == 4); fail_unless(entry.compressed_size == 4); fail_unless(entry.is_compressed == 0); fail_unless(isErrorPresent(&errmem) == 0, getLastErrorString(&errmem)); fail_unless(streampos == ftell(fileptr)); initErrorMemory(&errmem, buffer, 512); hqr_readItem(&errmem, fileptr, 1, compbuf, 512, uncompbuf, 512); fail_unless(isErrorPresent(&errmem) == 0); fail_unless(streampos == ftell(fileptr)); fclose(fileptr); }
jzfile * ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified, jboolean usemmap) { char errbuf[256]; jlong len; jzfile *zip; if ((zip = allocZip(name)) == NULL) { return NULL; } #ifdef USE_MMAP zip->usemmap = usemmap; #endif zip->refs = 1; zip->lastModified = lastModified; if (zfd == -1) { if (pmsg && getLastErrorString(errbuf, sizeof(errbuf)) > 0) *pmsg = strdup(errbuf); freeZip(zip); return NULL; } // Assumption, zfd refers to start of file. Trivially, reuse errbuf. if (readFully(zfd, errbuf, 4) != -1) { // errors will be handled later zip->locsig = LOCSIG_AT(errbuf) ? JNI_TRUE : JNI_FALSE; } len = zip->len = IO_Lseek(zfd, 0, SEEK_END); if (len <= 0) { if (len == 0) { /* zip file is empty */ if (pmsg) { *pmsg = strdup("zip file is empty"); } } else { /* error */ if (pmsg && getLastErrorString(errbuf, sizeof(errbuf)) > 0) *pmsg = strdup(errbuf); } ZFILE_Close(zfd); freeZip(zip); return NULL; } zip->zfd = zfd; if (readCEN(zip, -1) < 0) { /* An error occurred while trying to read the zip file */ if (pmsg != 0) { /* Set the zip error message */ if (zip->msg != NULL) *pmsg = strdup(zip->msg); } freeZip(zip); return NULL; } MLOCK(zfiles_lock); zip->next = zfiles; zfiles = zip; MUNLOCK(zfiles_lock); return zip; }
string DBClientWithCommands::getLastError() { BSONObj info = getLastErrorDetailed(); return getLastErrorString( info ); }
bool copy_file(const path & from_p, const path & to_p, bool overwrite) { bool ret = CopyFileA(from_p.string().c_str(), to_p.string().c_str(), !overwrite) == TRUE; if(!ret) { LogWarning << "CopyFileA(" << from_p << ", " << to_p << ", " << !overwrite << ") failed! " << getLastErrorString(); } else { update_last_write_time(to_p); } return ret; }