static void splitDatabase(const std::string& outputPath, const std::string& inputFileName, size_t trainingSamples, size_t validationSamples, bool groupByLabel, const std::string& labelPrefix) { database::SampleDatabase inputDatabase(inputFileName); inputDatabase.load(); if(groupByLabel) { createDirectories(outputPath, "training", inputDatabase.getAllPossibleLabels()); createDirectories(outputPath, "validation", inputDatabase.getAllPossibleLabels()); } else { util::makeDirectory(util::joinPaths(outputPath, "training")); util::makeDirectory(util::joinPaths(outputPath, "validation")); } database::SampleDatabase trainingDatabase(util::joinPaths(outputPath, util::joinPaths("training", "database.txt"))); database::SampleDatabase validationDatabase(util::joinPaths(outputPath, util::joinPaths("validation", "database.txt"))); randomlyShuffleSamples(trainingDatabase, validationDatabase, inputDatabase, trainingSamples, validationSamples, groupByLabel, labelPrefix); trainingDatabase.save(); validationDatabase.save(); }
bool createDirectories(const cv::String& path_) { cv::String path = path_; for (;;) { char last_char = path.empty() ? 0 : path[path.length() - 1]; if (isPathSeparator(last_char)) { path = path.substr(0, path.length() - 1); continue; } break; } if (path.empty() || path == "./" || path == ".\\" || path == ".") return true; if (isDirectory(path)) return true; size_t pos = path.rfind('/'); if (pos == cv::String::npos) pos = path.rfind('\\'); if (pos != cv::String::npos) { cv::String parent_directory = path.substr(0, pos); if (!parent_directory.empty()) { if (!createDirectories(parent_directory)) return false; } } return createDirectory(path); }
VideoFrameSource_sV::VideoFrameSource_sV(const Project_sV *project, const QString &filename) throw(FrameSourceError) : AbstractFrameSource_sV(project), m_inFile(filename), m_fps(1,1), m_ffmpegSemaphore(1), m_initialized(false) { if (!QFileInfo(filename).exists()) { throw FrameSourceError(tr("Video file %1 does not exist!").arg(filename)); } m_videoInfo = new VideoInfoSV(); *m_videoInfo = getInfo(filename.toStdString().c_str()); if (m_videoInfo->streamsCount <= 0) { qDebug() << "Video info is invalid: " << filename; throw FrameSourceError(tr("Video is invalid, no streams found in %1").arg(filename)); } m_fps = Fps_sV(m_videoInfo->frameRateNum, m_videoInfo->frameRateDen); createDirectories(); locateFFmpeg(); m_ffmpeg = new QProcess(this); m_timer = new QTimer(this); bool b = true; b &= connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProgressUpdate())); Q_ASSERT(b); }
void VideoFrameSource_sV::slotUpdateProjectDir() { // Delete old directories if they are empty m_dirFramesSmall.rmdir("."); m_dirFramesOrig.rmdir("."); createDirectories(); }
void File::create() const { const boost::filesystem::path abs = boost::filesystem::absolute(path); const boost::filesystem::path dir = abs.parent_path(); createDirectories(dir); mknod(); chown(); }
ImagesFrameSource_sV::ImagesFrameSource_sV(Project_sV *project, QStringList images) throw(FrameSourceError) : AbstractFrameSource_sV(project), m_fps(24, 1), m_initialized(false), m_stopInitialization(false), m_nextFrame(0) { QString msg = validateImages(images); if (msg.length() > 0) { throw FrameSourceError("Image frame source: " + msg); } m_imagesList.append(images); m_imagesList.sort(); QImage repImage(m_imagesList.at(0)); if (repImage.isNull()) { qDebug() << "Image is null: " << m_imagesList.at(0); qDebug() << "Supported image formats: " << QImageReader::supportedImageFormats(); throw FrameSourceError(QString("Cannot read image: %1").arg(m_imagesList.at(0))); } m_sizeSmall = repImage.size(); if (m_sizeSmall.isEmpty()) { throw FrameSourceError(QString("Image read from %1 is empty.").arg(m_imagesList.at(0))); } while (m_sizeSmall.width() > 600) { m_sizeSmall = m_sizeSmall/2; } createDirectories(); }
FileHandler::FileHandler(const std::string& dataRt, const std::string& resultRt, int rt_depth, bool setupDirectories) : m_input_root(dataRt), m_output_root(resultRt), m_root_depth(rt_depth), m_inputFolders(getInputFoldernames()), m_outputFolders(m_inputFolders), m_showProcessing(false), m_inputSuffix(".jpg"), m_inputPrefix("in"), m_outputSuffix(".png"), m_outputPrefix("bin") { setOutputFolders(); if(setupDirectories) createDirectories(); }
/** * Creates the directory structure in output_dir/ * * @param output_dir the directory into which the files should be placed * @param image_dir the directory where the image files are located for * relocation */ KMLBuilder::KMLBuilder(QDir output_dir, QDir image_dir) { output_directory = output_dir; image_directory = image_dir; fileDirs["root"] = new QDir(output_dir); readTemplates(); createDirectories(); }
void PrintDialogController::initOptions() { setOptions(); if(getSaveToPdf()) { createDirectories(); } }
// Create a directories recursively FXbool FXDir::createDirectories(const FXString& path,FXuint perm){ FXTRACE((1,"path=%s\n",path.text())); if(!path.empty()){ if(FXStat::isDirectory(path)) return true; if(createDirectories(FXPath::upLevel(path),perm)){ if(FXDir::create(path,perm)) return true; } } return false; }
bool createFile(const char* filePathAndName, bool overwriteExisting) { if (overwriteExisting && fileExists(filePathAndName)) { return std::ifstream(filePathAndName, std::fstream::in | std::fstream::trunc).good(); } const SysInfo& systemInfo = const_sysInfo(); createDirectories((systemInfo._pathAndFilename._path + "/" + splitPathToNameAndLocation(filePathAndName)._path).c_str()); return std::ifstream(filePathAndName, std::fstream::in).good(); }
void StorageTinyLog::truncate(const ASTPtr &, const Context &) { if (name.empty()) throw Exception("Logical error: table name is empty", ErrorCodes::LOGICAL_ERROR); auto file = Poco::File(path + escapeForFileName(name)); file.remove(true); file.createDirectories(); files.clear(); file_checker = FileChecker{path + escapeForFileName(name) + '/' + "sizes.json"}; for (const auto &column : getColumns().getAllPhysical()) addFiles(column.name, *column.type); }
bool writeFile(const stringImpl& filePath, const stringImpl& fileName, const bufferPtr content, size_t length, FileType fileType) { if (!filePath.empty() && content != nullptr && length > 0) { if (!pathExists(filePath.c_str())) { if (!createDirectories(filePath.c_str())) { return false; } } std::ofstream outputFile((filePath + fileName).c_str(), fileType == FileType::BINARY ? std::ios::out | std::ios::binary : std::ios::out); outputFile.write(reinterpret_cast<char*>(content), length); outputFile.close(); return outputFile.good(); } return false; }
ImagesFrameSource_sV::ImagesFrameSource_sV(Project_sV *project, QStringList images) throw(FrameSourceError) : AbstractFrameSource_sV(project), m_fps(24, 1), m_initialized(false), m_stopInitialization(false), m_nextFrame(0) { QString msg = validateImages(images); if (msg.length() > 0) { throw FrameSourceError("Image frame source: " + msg); } m_imagesList.append(images); m_imagesList.sort(); m_sizeSmall = QImage(m_imagesList.at(0)).size(); while (m_sizeSmall.width() > 600) { m_sizeSmall = m_sizeSmall/2; } createDirectories(); }
/* * This function initiates the KML build process. */ int main(int argc, char** argv) { if (*(++argv) == NULL) { qDebug() << "\aERROR Improper Usage!!!" << endl << endl; qDebug() << "Correct Usage:" << endl; qDebug() << "kmlbuilder FILE_DIRECTORY_NAME" << endl; return EXIT_FAILURE; } executableDir = new QDir("."); filePath = new QString(*argv); subDirName[ROOT] = *filePath; fileDir[ROOT] = new QDir(*filePath); if (!fileDir[ROOT]->exists()) { qDebug() << *filePath << "\a NOT FOUND!!!" << endl; return EXIT_FAILURE; } if (!readTemplates()) return EXIT_FAILURE; if (!createDirectories()) return EXIT_FAILURE; generateFiles(); if (!relocateImages()) return EXIT_FAILURE; for (int i = 0; i < 4; i++) delete fileDir[i]; delete filePath; delete executableDir; return EXIT_SUCCESS; }
void SzbParamMonitorTest::renameTest() { SzbParamMonitor m; TestObserver o1; int fd = -1; std::vector<std::string> dir_paths = createDirectories(); m.add_observer(&o1, std::vector<std::pair<TParam*, std::vector<std::string> > >(1, std::make_pair((TParam*)1, dir_paths)), 0); CPPUNIT_ASSERT_NO_THROW(fd = sz4::open_writelock((dir_paths[0] + "/f.tmp").c_str(), O_WRONLY | O_CREAT | O_BINARY)); write(fd, "1111", 4); sz4::close_unlock(fd); CPPUNIT_ASSERT_NO_THROW(fd = sz4::open_writelock((dir_paths[1] + "/f.tmp").c_str(), O_WRONLY | O_CREAT | O_BINARY)); write(fd, "1111", 4); sz4::close_unlock(fd); boost::filesystem::rename(dir_paths[0] + "/f.tmp", dir_paths[0] + "/11.sz4"); boost::filesystem::rename(dir_paths[1] + "/f.tmp", dir_paths[1] + "/11.sz4"); CPPUNIT_ASSERT(o1.wait_for(2)); CPPUNIT_ASSERT_EQUAL(size_t(1), o1.map.size()); CPPUNIT_ASSERT_EQUAL(2, o1.map[(TParam*)1]); }
bool FileUtils::writeStringToFile(const std::string& content, const std::string& fullpath) { size_t pos = fullpath.find_last_of("\\/"); if (pos == std::string::npos) { return false; } std::string dir = fullpath.substr(0, pos); if (!isExist(dir)) { createDirectories(dir); } FILE* fp = fopen(fullpath.c_str(), "wb"); if (nullptr == fp) { return false; } fwrite(content.data(), content.length(), 1, fp); fclose(fp); return true; }
void fsExperiments::setupParams() { fs::path paramsXml( getAssetPath( "params.xml" )); if ( paramsXml.empty() ) { #if defined( CINDER_MAC ) fs::path assetPath( getResourcePath() / "assets" ); #else fs::path assetPath( getAppPath() / "assets" ); #endif createDirectories( assetPath ); paramsXml = assetPath / "params.xml" ; } params::PInterfaceGl::load( paramsXml ); GlobalData& data = GlobalData::get(); data.mParams = params::PInterfaceGl( "Parameters", Vec2i( 200, 300 ) ); data.mParams.addPersistentSizeAndPosition(); data.mParams.addParam( "Fps", &mFps, "", false ); data.mParams.addPersistentParam( "Background", &mBackground, Color::gray( .1 ) ); // effect params setup mCurrentEffect = 0; vector< string > effectNames; for ( vector< fsExpRef >::iterator it = mEffects.begin(); it != mEffects.end(); ++it ) { effectNames.push_back( (*it)->getName() ); } data.mParams.addParam( "Effect", effectNames, &mCurrentEffect ); for ( vector< fsExpRef >::iterator it = mEffects.begin(); it != mEffects.end(); ++it ) { (*it)->setupParams(); } }
void SzbParamMonitorTest::writeTest() { SzbParamMonitor m; TestObserver o1, o2; int fd = -1; std::vector<std::string> dir_paths = createDirectories(); m.add_observer(&o1, std::vector<std::pair<TParam*, std::vector<std::string> > >(1, std::make_pair((TParam*)1, dir_paths)), 0); for (std::vector<std::string>::iterator i = dir_paths.begin(); i != dir_paths.end(); i++) { std::string s = *i + "/test.sz4"; CPPUNIT_ASSERT_NO_THROW(fd = sz4::open_writelock(s.c_str(), O_WRONLY | O_CREAT | O_BINARY)); write(fd, "1111", 4); sz4::close_unlock(fd); } CPPUNIT_ASSERT(o1.wait_for(3)); CPPUNIT_ASSERT_EQUAL(size_t(1), o1.map.size()); CPPUNIT_ASSERT_EQUAL(3, o1.map[(TParam*)1]); m.add_observer(&o1, std::vector<std::pair<TParam*, std::vector<std::string> > >(1, std::make_pair((TParam*)2, dir_paths)), 0); m.add_observer(&o2, std::vector<std::pair<TParam*, std::vector<std::string> > >(1, std::make_pair((TParam*)2, dir_paths)), 0); for (std::vector<std::string>::iterator i = dir_paths.begin(); i != dir_paths.end(); i++) { std::string s = *i + "/test.sz4"; CPPUNIT_ASSERT_NO_THROW(fd = sz4::open_writelock(s.c_str(), O_WRONLY | O_BINARY)); write(fd, "1111", 4); sz4::close_unlock(fd); } CPPUNIT_ASSERT(o1.wait_for(9)); CPPUNIT_ASSERT_EQUAL(size_t(2), o1.map.size()); CPPUNIT_ASSERT_EQUAL(6, o1.map[(TParam*)1]); CPPUNIT_ASSERT_EQUAL(3, o1.map[(TParam*)2]); CPPUNIT_ASSERT(o2.wait_for(3)); CPPUNIT_ASSERT_EQUAL(size_t(1), o2.map.size()); CPPUNIT_ASSERT_EQUAL(3, o2.map[(TParam*)2]); m.remove_observer(&o1); for (std::vector<std::string>::iterator i = dir_paths.begin(); i != dir_paths.end(); i++) { std::string s = *i + "/test.sz4"; CPPUNIT_ASSERT_NO_THROW(fd = sz4::open_writelock(s.c_str(), O_WRONLY | O_BINARY)); write(fd, "1111", 4); sz4::close_unlock(fd); } CPPUNIT_ASSERT_EQUAL(size_t(2), o1.map.size()); CPPUNIT_ASSERT_EQUAL(6, o1.map[(TParam*)1]); CPPUNIT_ASSERT_EQUAL(3, o1.map[(TParam*)2]); CPPUNIT_ASSERT(o2.wait_for(6)); CPPUNIT_ASSERT_EQUAL(size_t(1), o2.map.size()); CPPUNIT_ASSERT_EQUAL(6, o2.map[(TParam*)2]); boost::filesystem::remove_all(boost::filesystem::path(dir_paths[0]).branch_path()); }
void Win32AsyncFile::openReq(Request* request) { m_auto_sync_freq = 0; m_write_wo_sync = 0; m_open_flags = request->par.open.flags; // for open.flags, see signal FSOPENREQ DWORD dwCreationDisposition; DWORD dwDesiredAccess = 0; DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; /** * FIXME: * Previously we had FILE_FLAG_NO_BUFFERING also set here. * This has similar alignment rules to O_DIRECT on 2.4 kernels. * which means we should obey the directio req as we can't do it * everywhere (this seemingly "worked" in 5.0 though), e.g. by default * LCP isn't aligned IO. */ DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS; Uint32 flags = request->par.open.flags; // Convert file open flags from Solaris to Windows if ((flags & FsOpenReq::OM_CREATE) && (flags & FsOpenReq::OM_TRUNCATE)){ dwCreationDisposition = CREATE_ALWAYS; } else if (flags & FsOpenReq::OM_TRUNCATE){ dwCreationDisposition = TRUNCATE_EXISTING; } else if (flags & (FsOpenReq::OM_CREATE|FsOpenReq::OM_CREATE_IF_NONE)){ dwCreationDisposition = CREATE_NEW; } else { dwCreationDisposition = OPEN_EXISTING; } switch(flags & 3){ case FsOpenReq::OM_READONLY: dwDesiredAccess = GENERIC_READ; break; case FsOpenReq::OM_WRITEONLY: dwDesiredAccess = GENERIC_WRITE; break; case FsOpenReq::OM_READWRITE: dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; break; default: request->error = 1000; break; return; } hFile = CreateFile(theFileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0); if(INVALID_HANDLE_VALUE == hFile) { request->error = GetLastError(); if(((ERROR_PATH_NOT_FOUND == request->error) || (ERROR_INVALID_NAME == request->error)) && (flags & (FsOpenReq::OM_CREATE|FsOpenReq::OM_CREATE_IF_NONE))) { createDirectories(); hFile = CreateFile(theFileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0); if(INVALID_HANDLE_VALUE == hFile) request->error = GetLastError(); else request->error = 0; } } else { request->error = 0; } if (flags & FsOpenReq::OM_INIT) { LARGE_INTEGER off; off.QuadPart= 0; LARGE_INTEGER sz; sz.QuadPart= request->par.open.file_size; char buf[4096]; bzero(buf,sizeof(buf)); while(off.QuadPart < sz.QuadPart) { BOOL r= SetFilePointerEx(hFile, off, NULL, FILE_BEGIN); if(r==0) { request->error= GetLastError(); return; } DWORD dwWritten; BOOL bWrite= WriteFile(hFile, buf, sizeof(buf), &dwWritten, 0); if(!bWrite || dwWritten!=sizeof(buf)) { request->error= GetLastError(); } off.QuadPart+=sizeof(buf); } off.QuadPart= 0; BOOL r= SetFilePointerEx(hFile, off, NULL, FILE_BEGIN); if(r==0) { request->error= GetLastError(); return; } /* Write initial data */ SignalT<25> tmp; Signal * signal = (Signal*)(&tmp); bzero(signal, sizeof(tmp)); FsReadWriteReq* req = (FsReadWriteReq*)signal->getDataPtrSend(); Uint32 index = 0; Uint32 block = refToMain(request->theUserReference); Uint32 instance = refToInstance(request->theUserReference); off.QuadPart= 0; sz.QuadPart= request->par.open.file_size; while(off.QuadPart < sz.QuadPart) { req->filePointer = 0; // DATA 0 req->userPointer = request->theUserPointer; // DATA 2 req->numberOfPages = 1; // DATA 5 req->varIndex = index++; req->data.pageData[0] = m_page_ptr.i; m_fs.EXECUTE_DIRECT(block, GSN_FSWRITEREQ, signal, FsReadWriteReq::FixedLength + 1, instance // wl4391_todo This EXECUTE_DIRECT is thread safe ); Uint32 size = request->par.open.page_size; char* buf = (char*)m_page_ptr.p; DWORD dwWritten; while(size > 0){ BOOL bWrite= WriteFile(hFile, buf, size, &dwWritten, 0); if(!bWrite || dwWritten!=size) { request->error= GetLastError(); } size -= dwWritten; buf += dwWritten; } if(size != 0) { int err = errno; /* close(theFd); unlink(theFileName.c_str());*/ request->error = err; return; } off.QuadPart += request->par.open.page_size; } off.QuadPart= 0; r= SetFilePointerEx(hFile, off, NULL, FILE_BEGIN); if(r==0) { request->error= GetLastError(); return; } } return; }
void AsyncFile::openReq(Request* request) { m_auto_sync_freq = 0; m_write_wo_sync = 0; m_open_flags = request->par.open.flags; // for open.flags, see signal FSOPENREQ #ifdef NDB_WIN32 DWORD dwCreationDisposition; DWORD dwDesiredAccess = 0; DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_NO_BUFFERING; Uint32 flags = request->par.open.flags; // Convert file open flags from Solaris to Windows if ((flags & FsOpenReq::OM_CREATE) && (flags & FsOpenReq::OM_TRUNCATE)){ dwCreationDisposition = CREATE_ALWAYS; } else if (flags & FsOpenReq::OM_TRUNCATE){ dwCreationDisposition = TRUNCATE_EXISTING; } else if (flags & FsOpenReq::OM_CREATE){ dwCreationDisposition = CREATE_NEW; } else { dwCreationDisposition = OPEN_EXISTING; } switch(flags & 3){ case FsOpenReq::OM_READONLY: dwDesiredAccess = GENERIC_READ; break; case FsOpenReq::OM_WRITEONLY: dwDesiredAccess = GENERIC_WRITE; break; case FsOpenReq::OM_READWRITE: dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; break; default: request->error = 1000; break; return; } hFile = CreateFile(theFileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0); if(INVALID_HANDLE_VALUE == hFile) { request->error = GetLastError(); if(((ERROR_PATH_NOT_FOUND == request->error) || (ERROR_INVALID_NAME == request->error)) && (flags & FsOpenReq::OM_CREATE)) { createDirectories(); hFile = CreateFile(theFileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0); if(INVALID_HANDLE_VALUE == hFile) request->error = GetLastError(); else request->error = 0; return; } } else { request->error = 0; return; } #else Uint32 flags = request->par.open.flags; int new_flags = 0; // Convert file open flags from Solaris to Liux if (flags & FsOpenReq::OM_CREATE) { new_flags |= O_CREAT; } if (flags & FsOpenReq::OM_TRUNCATE){ #if 0 if(Global_unlinkO_CREAT){ unlink(theFileName.c_str()); } else #endif new_flags |= O_TRUNC; } if (flags & FsOpenReq::OM_AUTOSYNC) { m_auto_sync_freq = request->par.open.auto_sync_size; } if (flags & FsOpenReq::OM_APPEND){ new_flags |= O_APPEND; } if (flags & FsOpenReq::OM_DIRECT) #ifdef O_DIRECT { new_flags |= O_DIRECT; } #endif if ((flags & FsOpenReq::OM_SYNC) && ! (flags & FsOpenReq::OM_INIT)) { #ifdef O_SYNC new_flags |= O_SYNC; #endif } const char * rw = ""; switch(flags & 0x3){ case FsOpenReq::OM_READONLY: rw = "r"; new_flags |= O_RDONLY; break; case FsOpenReq::OM_WRITEONLY: rw = "w"; new_flags |= O_WRONLY; break; case FsOpenReq::OM_READWRITE: rw = "rw"; new_flags |= O_RDWR; break; default: request->error = 1000; break; return; } // allow for user to choose any permissionsa with umask const int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; if (flags & FsOpenReq::OM_CREATE_IF_NONE) { Uint32 tmp_flags = new_flags; #ifdef O_DIRECT tmp_flags &= ~O_DIRECT; #endif if ((theFd = ::open(theFileName.c_str(), tmp_flags, mode)) != -1) { close(theFd); request->error = FsRef::fsErrFileExists; return; } new_flags |= O_CREAT; } no_odirect: if (-1 == (theFd = ::open(theFileName.c_str(), new_flags, mode))) { PRINT_ERRORANDFLAGS(new_flags); if ((errno == ENOENT) && (new_flags & O_CREAT)) { createDirectories(); if (-1 == (theFd = ::open(theFileName.c_str(), new_flags, mode))) { #ifdef O_DIRECT if (new_flags & O_DIRECT) { new_flags &= ~O_DIRECT; goto no_odirect; } #endif PRINT_ERRORANDFLAGS(new_flags); request->error = errno; return; } } #ifdef O_DIRECT else if (new_flags & O_DIRECT) { new_flags &= ~O_DIRECT; goto no_odirect; } #endif else { request->error = errno; return; } } if (flags & FsOpenReq::OM_CHECK_SIZE) { struct stat buf; if ((fstat(theFd, &buf) == -1)) { request->error = errno; } else if((Uint64)buf.st_size != request->par.open.file_size) { request->error = FsRef::fsErrInvalidFileSize; } if (request->error) return; } if (flags & FsOpenReq::OM_INIT) { off_t off = 0; const off_t sz = request->par.open.file_size; Uint32 tmp[sizeof(SignalHeader)+25]; Signal * signal = (Signal*)(&tmp[0]); FsReadWriteReq* req = (FsReadWriteReq*)signal->getDataPtrSend(); Uint32 index = 0; Uint32 block = refToBlock(request->theUserReference); #ifdef HAVE_XFS_XFS_H if(platform_test_xfs_fd(theFd)) { ndbout_c("Using xfsctl(XFS_IOC_RESVSP64) to allocate disk space"); xfs_flock64_t fl; fl.l_whence= 0; fl.l_start= 0; fl.l_len= (off64_t)sz; if(xfsctl(NULL, theFd, XFS_IOC_RESVSP64, &fl) < 0) ndbout_c("failed to optimally allocate disk space"); } #endif #ifdef HAVE_POSIX_FALLOCATE posix_fallocate(theFd, 0, sz); #endif while(off < sz) { req->filePointer = 0; // DATA 0 req->userPointer = request->theUserPointer; // DATA 2 req->numberOfPages = 1; // DATA 5 req->varIndex = index++; req->data.pageData[0] = m_page_ptr.i; m_fs.EXECUTE_DIRECT(block, GSN_FSWRITEREQ, signal, FsReadWriteReq::FixedLength + 1); retry: Uint32 size = request->par.open.page_size; char* buf = (char*)m_page_ptr.p; while(size > 0){ const int n = write(theFd, buf, size); if(n == -1 && errno == EINTR) { continue; } if(n == -1 || n == 0) { break; } size -= n; buf += n; } if(size != 0) { int err = errno; #ifdef O_DIRECT if ((new_flags & O_DIRECT) && off == 0) { ndbout_c("error on first write(%d), disable O_DIRECT", err); new_flags &= ~O_DIRECT; close(theFd); theFd = ::open(theFileName.c_str(), new_flags, mode); if (theFd != -1) goto retry; } #endif close(theFd); unlink(theFileName.c_str()); request->error = err; return; } off += request->par.open.page_size; } if(lseek(theFd, 0, SEEK_SET) != 0) request->error = errno; } else if (flags & FsOpenReq::OM_DIRECT) { #ifdef O_DIRECT if (flags & (FsOpenReq::OM_TRUNCATE | FsOpenReq::OM_CREATE)) { request->error = check_odirect_write(flags, new_flags, mode); } else { request->error = check_odirect_read(flags, new_flags, mode); } if (request->error) return; #endif } #ifdef VM_TRACE if (flags & FsOpenReq::OM_DIRECT) { #ifdef O_DIRECT ndbout_c("%s %s O_DIRECT: %d", theFileName.c_str(), rw, !!(new_flags & O_DIRECT)); #else ndbout_c("%s %s O_DIRECT: 0", theFileName.c_str(), rw); #endif } #endif if ((flags & FsOpenReq::OM_SYNC) && (flags & FsOpenReq::OM_INIT)) { #ifdef O_SYNC /** * reopen file with O_SYNC */ close(theFd); new_flags &= ~(O_CREAT | O_TRUNC); new_flags |= O_SYNC; theFd = ::open(theFileName.c_str(), new_flags, mode); if (theFd == -1) { request->error = errno; } #endif } #endif }
cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name) { String cache_path; if (configuration_name) { cache_path = utils::getConfigurationParameterString(configuration_name, ""); } if (cache_path.empty()) { cv::String default_cache_path; #ifdef _WIN32 char tmp_path_buf[MAX_PATH+1] = {0}; DWORD res = GetTempPath(MAX_PATH, tmp_path_buf); if (res > 0 && res <= MAX_PATH) { default_cache_path = tmp_path_buf; } #elif defined __ANDROID__ // no defaults #elif defined __APPLE__ const char* tmpdir_env = getenv("TMPDIR"); if (tmpdir_env && utils::fs::isDirectory(tmpdir_env)) { default_cache_path = tmpdir_env; } else { default_cache_path = "/tmp/"; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } #elif defined __linux__ // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if (default_cache_path.empty()) { const char* xdg_cache_env = getenv("XDG_CACHE_HOME"); if (xdg_cache_env && xdg_cache_env[0] && utils::fs::isDirectory(xdg_cache_env)) { default_cache_path = xdg_cache_env; } } if (default_cache_path.empty()) { const char* home_env = getenv("HOME"); if (home_env && home_env[0] && utils::fs::isDirectory(home_env)) { cv::String home_path = home_env; cv::String home_cache_path = home_path + "/.cache/"; if (utils::fs::isDirectory(home_cache_path)) { default_cache_path = home_cache_path; } } } if (default_cache_path.empty()) { const char* temp_path = "/var/tmp/"; if (utils::fs::isDirectory(temp_path)) { default_cache_path = temp_path; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } } if (default_cache_path.empty()) { default_cache_path = "/tmp/"; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } #else // no defaults #endif CV_LOG_VERBOSE(NULL, 0, "default_cache_path = " << default_cache_path); if (!default_cache_path.empty()) { if (utils::fs::isDirectory(default_cache_path)) { default_cache_path += "/opencv/" CV_VERSION "/"; if (sub_directory_name && sub_directory_name[0] != '\0') default_cache_path += cv::String(sub_directory_name) + "/"; if (!utils::fs::createDirectories(default_cache_path)) { CV_LOG_DEBUG(NULL, "Can't create OpenCV cache sub-directory: " << default_cache_path); } else { cache_path = default_cache_path; } } else { CV_LOG_INFO(NULL, "Can't find default cache directory (does it exist?): " << default_cache_path); } } else { CV_LOG_DEBUG(NULL, "OpenCV has no support to discover default cache directory on the current platform"); } } else { if (cache_path == "disabled") return cache_path; if (!isDirectory(cache_path)) { CV_LOG_WARNING(NULL, "Specified non-existed directory, creating OpenCV sub-directory for caching purposes: " << cache_path); if (!createDirectories(cache_path)) { CV_LOG_ERROR(NULL, "Can't create OpenCV cache sub-directory: " << cache_path); cache_path.clear(); } } } CV_Assert(cache_path.empty() || utils::fs::isDirectory(cache_path)); if (!cache_path.empty()) { if (!isPathSeparator(cache_path[cache_path.size() - 1])) { cache_path += '/'; } } return cache_path; }
cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name) { String cache_path; if (configuration_name) { cache_path = utils::getConfigurationParameterString(configuration_name, ""); } if (cache_path.empty()) { cv::String default_cache_path; #ifdef _WIN32 char tmp_path_buf[MAX_PATH+1] = {0}; DWORD res = GetTempPath(MAX_PATH, tmp_path_buf); if (res > 0 && res <= MAX_PATH) { default_cache_path = tmp_path_buf; } #elif defined __ANDROID__ // no defaults #elif defined __APPLE__ const char* tmpdir_env = getenv("TMPDIR"); if (tmpdir_env && utils::fs::isDirectory(tmpdir_env)) { default_cache_path = tmpdir_env; } else { default_cache_path = "/tmp/"; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } #elif defined __linux__ || defined __HAIKU__ || defined __FreeBSD__ // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if (default_cache_path.empty()) { const char* xdg_cache_env = getenv("XDG_CACHE_HOME"); if (xdg_cache_env && xdg_cache_env[0] && utils::fs::isDirectory(xdg_cache_env)) { default_cache_path = xdg_cache_env; } } if (default_cache_path.empty()) { const char* home_env = getenv("HOME"); if (home_env && home_env[0] && utils::fs::isDirectory(home_env)) { cv::String home_path = home_env; cv::String home_cache_path = utils::fs::join(home_path, ".cache/"); if (utils::fs::isDirectory(home_cache_path)) { default_cache_path = home_cache_path; } } } if (default_cache_path.empty()) { const char* temp_path = "/var/tmp/"; if (utils::fs::isDirectory(temp_path)) { default_cache_path = temp_path; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } } if (default_cache_path.empty()) { default_cache_path = "/tmp/"; CV_LOG_WARNING(NULL, "Using world accessible cache directory. This may be not secure: " << default_cache_path); } #else // no defaults #endif CV_LOG_VERBOSE(NULL, 0, "default_cache_path = " << default_cache_path); if (!default_cache_path.empty()) { if (utils::fs::isDirectory(default_cache_path)) { cv::String default_cache_path_base = utils::fs::join(default_cache_path, "opencv"); default_cache_path = utils::fs::join(default_cache_path_base, "4.0" CV_VERSION_STATUS); if (utils::getConfigurationParameterBool("OPENCV_CACHE_SHOW_CLEANUP_MESSAGE", true) && !utils::fs::isDirectory(default_cache_path)) { std::vector<cv::String> existedCacheDirs; try { utils::fs::glob_relative(default_cache_path_base, "*", existedCacheDirs, false, true); } catch (...) { // ignore } if (!existedCacheDirs.empty()) { CV_LOG_WARNING(NULL, "Creating new OpenCV cache directory: " << default_cache_path); CV_LOG_WARNING(NULL, "There are several neighbour directories, probably created by old OpenCV versions."); CV_LOG_WARNING(NULL, "Feel free to cleanup these unused directories:"); for (size_t i = 0; i < existedCacheDirs.size(); i++) { CV_LOG_WARNING(NULL, " - " << existedCacheDirs[i]); } CV_LOG_WARNING(NULL, "Note: This message is showed only once."); } } if (sub_directory_name && sub_directory_name[0] != '\0') default_cache_path = utils::fs::join(default_cache_path, cv::String(sub_directory_name) + native_separator); if (!utils::fs::createDirectories(default_cache_path)) { CV_LOG_DEBUG(NULL, "Can't create OpenCV cache sub-directory: " << default_cache_path); } else { cache_path = default_cache_path; } } else { CV_LOG_INFO(NULL, "Can't find default cache directory (does it exist?): " << default_cache_path); } } else { CV_LOG_DEBUG(NULL, "OpenCV has no support to discover default cache directory on the current platform"); } } else { if (cache_path == "disabled") return cache_path; if (!isDirectory(cache_path)) { CV_LOG_WARNING(NULL, "Specified non-existed directory, creating OpenCV sub-directory for caching purposes: " << cache_path); if (!createDirectories(cache_path)) { CV_LOG_ERROR(NULL, "Can't create OpenCV cache sub-directory: " << cache_path); cache_path.clear(); } } } CV_Assert(cache_path.empty() || utils::fs::isDirectory(cache_path)); if (!cache_path.empty()) { if (!isPathSeparator(cache_path[cache_path.size() - 1])) { cache_path += native_separator; } } return cache_path; }
void AsyncFile::openReq(Request* request) { m_openedWithSync = false; m_syncFrequency = 0; m_syncCount= 0; // for open.flags, see signal FSOPENREQ #ifdef NDB_WIN32 DWORD dwCreationDisposition; DWORD dwDesiredAccess = 0; DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_NO_BUFFERING; const Uint32 flags = request->par.open.flags; // Convert file open flags from Solaris to Windows if ((flags & FsOpenReq::OM_CREATE) && (flags & FsOpenReq::OM_TRUNCATE)){ dwCreationDisposition = CREATE_ALWAYS; } else if (flags & FsOpenReq::OM_TRUNCATE){ dwCreationDisposition = TRUNCATE_EXISTING; } else if (flags & FsOpenReq::OM_CREATE){ dwCreationDisposition = CREATE_NEW; } else { dwCreationDisposition = OPEN_EXISTING; } switch(flags & 3){ case FsOpenReq::OM_READONLY: dwDesiredAccess = GENERIC_READ; break; case FsOpenReq::OM_WRITEONLY: dwDesiredAccess = GENERIC_WRITE; break; case FsOpenReq::OM_READWRITE: dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; break; default: request->error = 1000; break; return; } hFile = CreateFile(theFileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0); if(INVALID_HANDLE_VALUE == hFile) { request->error = GetLastError(); if(((ERROR_PATH_NOT_FOUND == request->error) || (ERROR_INVALID_NAME == request->error)) && (flags & FsOpenReq::OM_CREATE)) { createDirectories(); hFile = CreateFile(theFileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0); if(INVALID_HANDLE_VALUE == hFile) request->error = GetLastError(); else request->error = 0; return; } } else { request->error = 0; return; } #else const Uint32 flags = request->par.open.flags; Uint32 new_flags = 0; // Convert file open flags from Solaris to Liux if(flags & FsOpenReq::OM_CREATE){ new_flags |= O_CREAT; } if(flags & FsOpenReq::OM_TRUNCATE){ #if 0 if(Global_unlinkO_CREAT){ unlink(theFileName.c_str()); } else #endif new_flags |= O_TRUNC; } if(flags & FsOpenReq::OM_APPEND){ new_flags |= O_APPEND; } if(flags & FsOpenReq::OM_SYNC){ #if 0 if(Global_useO_SYNC){ new_flags |= O_SYNC; m_openedWithSync = true; m_syncFrequency = 0; } else { #endif m_openedWithSync = false; m_syncFrequency = Global_syncFreq; #if 0 } #endif } else { m_openedWithSync = false; m_syncFrequency = 0; } #if 0 //#if NDB_LINUX if(Global_useO_DIRECT){ new_flags |= O_DIRECT; } #endif switch(flags & 0x3){ case FsOpenReq::OM_READONLY: new_flags |= O_RDONLY; break; case FsOpenReq::OM_WRITEONLY: new_flags |= O_WRONLY; break; case FsOpenReq::OM_READWRITE: new_flags |= O_RDWR; break; default: request->error = 1000; break; return; } const int mode = S_IRUSR | S_IWUSR | S_IRGRP; if (-1 == (theFd = ::open(theFileName.c_str(), new_flags, mode))) { PRINT_ERRORANDFLAGS(new_flags); if( (errno == ENOENT ) && (new_flags & O_CREAT ) ) { createDirectories(); if (-1 == (theFd = ::open(theFileName.c_str(), new_flags, mode))) { PRINT_ERRORANDFLAGS(new_flags); request->error = errno; } } else { request->error = errno; } } #endif }
void Filesystem::createDirectoriesFor(const std::string& file) { createDirectories(dirname(file)); }
void ImagesFrameSource_sV::slotUpdateProjectDir() { m_dirImagesSmall.rmdir("."); createDirectories(); }
std::string Filesystem::createTemp() { std::string ret(append(getTemp(), Util::randomId())); createDirectories(ret); return ret; }
void startStopCallback(const std_msgs::Int16 startstopSignal) { // Start processing if(startstopSignal.data == 1) { detector.shouldProcess = true; if(firsttime) { firsttime = false; bool canCreateDir = false; if(!detector.usePreviousMemory) { canCreateDir = createDirectories(""); }else { canCreateDir = createDirectories(QString::fromStdString(detector.previousMemoryPath)); } if(canCreateDir) { qDebug()<<"Directories have been created successfully!!"; std_msgs::String sstr; sstr.data = mainDirectoryPath.toStdString(); std::cout<<"Ssstr data: "<<sstr.data<<std::endl; saveParameters(mainDirectoryPath); filePathPublisher.publish(sstr); } else { qDebug()<<"Error!! Necessary directories could not be created!! Detector will not work!!"; detector.shouldProcess = false; // return -1; } } } // Stop the node else if(startstopSignal.data == -1) { sendLastPlaceandShutdown = true; // ros::shutdown(); } // Pause the node else if(startstopSignal.data == 0) { detector.shouldProcess = false; } }