MeshPersonVisual::MeshPersonVisual(const PersonVisualDefaultArgs& args) : PersonVisual(args), m_animationState(NULL), m_walkingSpeed(1.0), entity_(NULL) { m_childSceneNode = m_sceneNode->createChildSceneNode(); m_childSceneNode->setVisible(false); std::string meshResource = "package://" ROS_PACKAGE_NAME "/media/animated_walking_man.mesh"; /// This is required to load referenced skeletons from package:// path fs::path model_path(meshResource); fs::path parent_path(model_path.parent_path()); Ogre::ResourceLoadingListener *newListener = new RosPackagePathResourceLoadingListener(parent_path), *oldListener = Ogre::ResourceGroupManager::getSingleton().getLoadingListener(); Ogre::ResourceGroupManager::getSingleton().setLoadingListener(newListener); bool loadFailed = rviz::loadMeshFromResource(meshResource).isNull(); Ogre::ResourceGroupManager::getSingleton().setLoadingListener(oldListener); delete newListener; // Create scene entity static size_t count = 0; std::stringstream ss; ss << "mesh_person_visual" << count++; std::string id = ss.str(); entity_ = m_sceneManager->createEntity(id, meshResource); m_childSceneNode->attachObject(entity_); // set up animation setAnimationState(""); // set up material ss << "Material"; Ogre::MaterialPtr default_material = Ogre::MaterialManager::getSingleton().create( ss.str(), "rviz" ); default_material->setReceiveShadows(false); default_material->getTechnique(0)->setLightingEnabled(true); default_material->getTechnique(0)->setAmbient( 0.5, 0.5, 0.5 ); materials_.insert( default_material ); entity_->setMaterial( default_material ); // set position Ogre::Quaternion quat1; quat1.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3(0,1,0)); Ogre::Quaternion quat2; quat2.FromAngleAxis(Ogre::Degree(-90), Ogre::Vector3(0,0,1)); m_childSceneNode->setOrientation(quat1 * quat2); double scaleFactor = 0.243 * 1.75; m_childSceneNode->setScale(Ogre::Vector3(scaleFactor, scaleFactor, scaleFactor)); m_childSceneNode->setPosition(Ogre::Vector3(0, 0, -1)); m_childSceneNode->setVisible(true); }
void move_log_file(std::string const& logpath, std::string const& new_name, int instance) { mutex::scoped_lock l(file_mutex); if (open_filename == m_filename) { log_file.close(); open_filename.clear(); } char log_name[512]; snprintf(log_name, sizeof(log_name), "libtorrent_logs%d", instance); std::string dir(combine_path(combine_path(complete(logpath), log_name), new_name) + ".log"); error_code ec; create_directories(parent_path(dir), ec); if (ec) fprintf(stderr, "Failed to create logfile directory %s: %s\n" , parent_path(dir).c_str(), ec.message().c_str()); ec.clear(); rename(m_filename, dir, ec); if (ec) fprintf(stderr, "Failed to move logfile %s: %s\n" , parent_path(dir).c_str(), ec.message().c_str()); m_filename = dir; }
logger(std::string const& logpath, std::string const& filename , int instance, bool append) { char log_name[512]; snprintf(log_name, sizeof(log_name), "libtorrent_logs%d", instance); std::string dir(complete(combine_path(combine_path(logpath, log_name), filename)) + ".log"); error_code ec; if (!exists(parent_path(dir))) create_directories(parent_path(dir), ec); m_filename = dir; mutex::scoped_lock l(file_mutex); open(!append); log_file << "\n\n\n*** starting log ***\n"; }
bool INotifyEventPublisher::monitorSubscription( INotifySubscriptionContextRef& sc, bool add_watch) { sc->discovered_ = sc->path; if (sc->path.find("**") != std::string::npos) { sc->recursive = true; sc->discovered_ = sc->path.substr(0, sc->path.find("**")); sc->path = sc->discovered_; } if (sc->path.find('*') != std::string::npos) { // If the wildcard exists within the file (leaf), remove and monitor the // directory instead. Apply a fnmatch on fired events to filter leafs. auto fullpath = fs::path(sc->path); if (fullpath.filename().string().find('*') != std::string::npos) { sc->discovered_ = fullpath.parent_path().string() + '/'; } if (sc->discovered_.find('*') != std::string::npos) { // If a wildcard exists within the tree (stem), resolve at configure // time and monitor each path. std::vector<std::string> paths; resolveFilePattern(sc->discovered_, paths); for (const auto& _path : paths) { addMonitor(_path, sc->mask, sc->recursive, add_watch); } sc->recursive_match = sc->recursive; return true; } } if (isDirectory(sc->discovered_) && sc->discovered_.back() != '/') { sc->path += '/'; sc->discovered_ += '/'; } return addMonitor(sc->discovered_, sc->mask, sc->recursive, add_watch); }
boost::filesystem::path Config::getDebugLogFile () const { auto log_file = DEBUG_LOGFILE; if (!log_file.empty () && !log_file.is_absolute ()) { // Unless an absolute path for the log file is specified, the // path is relative to the config file directory. log_file = boost::filesystem::absolute ( log_file, getConfig ().CONFIG_DIR); } if (!log_file.empty ()) { auto log_dir = log_file.parent_path (); if (!boost::filesystem::is_directory (log_dir)) { boost::system::error_code ec; boost::filesystem::create_directories (log_dir, ec); // If we fail, we warn but continue so that the calling code can // decide how to handle this situation. if (ec) { std::cerr << "Unable to create log file path " << log_dir << ": " << ec.message() << '\n'; } } } return log_file; }
inline void add_files(file_storage& fs, std::wstring const& wfile, boost::uint32_t flags = 0) { std::string utf8; wchar_utf8(wfile, utf8); detail::add_files_impl(fs, parent_path(complete(utf8)) , filename(utf8), detail::default_pred, flags); }
fs::path filestorage::get_parent_path(t_filestore file_type, const std::string &filename) { fs::path user_home(getenv("HOME")); fs::path parent_path(user_home.c_str()); switch (file_type) { case e_filestore_galaxy_wallet_PRV: { parent_path += "/.config/antinet/galaxy42/wallet/"; break; } case e_filestore_galaxy_pub: { parent_path += "/.config/antinet/galaxy42/public/"; break; } case e_filestore_galaxy_sig: { parent_path += "/.config/antinet/galaxy42/public/"; break; } case e_filestore_local_path: { fs::path file_path(filename); parent_path = file_path.parent_path(); break; } } return parent_path; }
void file_storage::update_path_index(internal_file_entry& e) { std::string parent = parent_path(e.filename()); if (parent.empty()) { e.path_index = -1; } else { // do we already have this path in the path list? std::vector<std::string>::reverse_iterator p = std::find(m_paths.rbegin(), m_paths.rend(), parent); if (p == m_paths.rend()) { // no, we don't. add it e.path_index = m_paths.size(); m_paths.push_back(parent); } else { // yes we do. use it e.path_index = p.base() - m_paths.begin() - 1; } e.set_name(filename(e.filename()).c_str()); } }
std::set<std::string> FSEventsEventPublisher::transformSubscription( FSEventsSubscriptionContextRef& sc) const { std::set<std::string> paths; sc->discovered_ = sc->path; if (sc->path.find("**") != std::string::npos) { // Double star will indicate recursive matches, restricted to endings. sc->recursive = true; sc->discovered_ = sc->path.substr(0, sc->path.find("**")); // Remove '**' from the subscription path (used to match later). sc->path = sc->discovered_; } // If the path 'still' OR 'either' contains a single wildcard. if (sc->path.find('*') != std::string::npos) { // First check if the wildcard is applied to the end. auto fullpath = fs::path(sc->path); if (fullpath.filename().string().find('*') != std::string::npos) { sc->discovered_ = fullpath.parent_path().string(); } // FSEvents needs a real path, if the wildcard is within the path then // a configure-time resolve is required. if (sc->discovered_.find('*') != std::string::npos) { std::vector<std::string> exploded_paths; resolveFilePattern(sc->discovered_, exploded_paths); for (const auto& path : exploded_paths) { paths.insert(path); } sc->recursive_match = sc->recursive; return paths; } } paths.insert(sc->discovered_); return paths; }
int CloudStitcher::setOutputPath( const std::string output_path ) { //make a boost path out of the provided path boost::filesystem::path fullname( output_path ); //split up the path into the file's parent directory path and the filename boost::filesystem::path parent_path( fullname.parent_path() ); boost::filesystem::path basename( fullname.filename() ); //check to make sure the parent directory actually exists and exit otherwise if( !boost::filesystem::is_directory( parent_path ) ) { std::stringstream output; output << "Error: specified output directory does not exist: " << parent_path.string() << "\n"; this->sendOutput( output.str() , true ); return -1; } //check to make sure the user gave us an actual filename to use std::string filename = basename.string(); if( filename.size() < 2 ) { this->sendOutput( "Error: no filename was specified.\n" , true ); return -1; } //if everything goes well, we will set the class member to the provided output path //for use later this->output_path = output_path; return 0; }
void WatcherRunner::createWorker() { { WatcherLocker locker; if (Watcher::getState(Watcher::getWorker()).last_respawn_time > getUnixTime() - getWorkerLimit(RESPAWN_LIMIT)) { LOG(WARNING) << "osqueryd worker respawning too quickly: " << Watcher::workerRestartCount() << " times"; Watcher::workerRestarted(); // The configured automatic delay. size_t delay = getWorkerLimit(RESPAWN_DELAY) * 1000; // Exponential back off for quickly-respawning clients. delay += pow(2, Watcher::workerRestartCount()) * 1000; pauseMilli(delay); } } // Get the path of the current process. auto qd = SQL::selectAllFrom("processes", "pid", EQUALS, INTEGER(PlatformProcess::getCurrentProcess()->pid())); if (qd.size() != 1 || qd[0].count("path") == 0 || qd[0]["path"].size() == 0) { LOG(ERROR) << "osquery watcher cannot determine process path for worker"; Initializer::requestShutdown(EXIT_FAILURE); return; } // Set an environment signaling to potential plugin-dependent workers to wait // for extensions to broadcast. if (Watcher::hasManagedExtensions()) { setEnvVar("OSQUERY_EXTENSIONS", "true"); } // Get the complete path of the osquery process binary. boost::system::error_code ec; auto exec_path = fs::system_complete(fs::path(qd[0]["path"]), ec); if (!safePermissions( exec_path.parent_path().string(), exec_path.string(), true)) { // osqueryd binary has become unsafe. LOG(ERROR) << RLOG(1382) << "osqueryd has unsafe permissions: " << exec_path.string(); Initializer::requestShutdown(EXIT_FAILURE); return; } auto worker = PlatformProcess::launchWorker(exec_path.string(), argc_, argv_); if (worker == nullptr) { // Unrecoverable error, cannot create a worker process. LOG(ERROR) << "osqueryd could not create a worker process"; Initializer::shutdown(EXIT_FAILURE); return; } Watcher::setWorker(worker); Watcher::resetWorkerCounters(getUnixTime()); VLOG(1) << "osqueryd watcher (" << PlatformProcess::getCurrentProcess()->pid() << ") executing worker (" << worker->pid() << ")"; }
TORRENT_DEPRECATED_PREFIX void TORRENT_DEPRECATED add_files(file_storage& fs, std::wstring const& wfile, Pred p, boost::uint32_t flags = 0) { std::string utf8; wchar_utf8(wfile, utf8); detail::add_files_impl(fs, parent_path(complete(utf8)) , filename(utf8), p, flags); }
void store( const Key& k, const Value& v ) { try { auto key_path = key_to_path(k); fc::create_directories( key_path.parent_path() ); auto data = fc::raw::pack( v ); FC_ASSERT( data.size() > 0 ); ofstream out( key_path ); out.writesome( data.data(), data.size() ); out.close(); } FC_CAPTURE_AND_RETHROW( (k)(v) ) }
void add_files_impl(file_storage& fs, std::string const& p , std::string const& l, boost::function<bool(std::string)> pred, boost::uint32_t flags) { std::string f = combine_path(p, l); if (!pred(f)) return; error_code ec; file_status s; stat_file(f, &s, ec, (flags & create_torrent::symlinks) ? dont_follow_links : 0); if (ec) return; // recurse into directories bool recurse = (s.mode & file_status::directory) != 0; // if the file is not a link or we're following links, and it's a directory // only then should we recurse #ifndef TORRENT_WINDOWS if ((s.mode & file_status::link) && (flags & create_torrent::symlinks)) recurse = false; #endif if (recurse) { fs.add_path(parent_path(combine_path(l, "x")), s.mode & 0777); for (directory i(f, ec); !i.done(); i.next(ec)) { std::string leaf = i.file(); if (ignore_subdir(leaf)) continue; add_files_impl(fs, p, combine_path(l, leaf), pred, flags); } } else if (s.mode & (file_status::regular_file | file_status::link)) { // #error use the fields from s int file_flags = get_file_attributes(f, (flags & create_torrent::symlinks) ? dont_follow_links : 0); // mask all bits to check if the file is a symlink if ((file_flags & file_storage::attribute_symlink) && (flags & create_torrent::symlinks)) { std::string sym_path = get_symlink_path(f); fs.add_file(l, 0, file_flags, s.mtime, sym_path, s.mode & 0777); } else { fs.add_file(l, s.file_size, file_flags, s.mtime, "", s.mode & 0777); } } if (fs.num_files() == 0) fs.set_name(l); }
std::string get_default_rpc_filepath () { boost::system::error_code err; auto running_executable_filepath = boost::dll::program_location (err); // Construct the nano_rpc excutable file path based on where the currently running executable is found. auto rpc_filepath = running_executable_filepath.parent_path () / "nano_rpc"; if (running_executable_filepath.has_extension ()) { rpc_filepath.replace_extension (running_executable_filepath.extension ()); } return rpc_filepath.string (); }
void CoreFS::removeFolder(std::string const &path, FolderRemovalType const &removalType) { StateLock lock(m_stateMutex); auto thePath(path); char ch = *path.rbegin(); // ignore trailing slash, but only if folder type // an entry of file type should never have a trailing // slash and is allowed to fail in this case if (ch == '/') { std::string(path.begin(), path.end() - 1).swap(thePath); } auto parentEntry(doGetParentCompoundFolder(thePath)); if (!parentEntry) { throw KnoxCryptException(KnoxCryptError::NotFound); } /* auto childInfo(parentEntry->getEntryInfo(boost::filesystem::path(thePath).filename().string())); if (!childInfo) { throw KnoxCryptException(KnoxCryptError::NotFound); } if (childInfo->type() == EntryType::FileType) { throw KnoxCryptException(KnoxCryptError::NotFound); }*/ auto boostPath = ::boost::filesystem::path(thePath); if (removalType == FolderRemovalType::MustBeEmpty) { auto childEntry(parentEntry->getFolder(boostPath.filename().string())); if (!childEntry->listAllEntries().empty()) { throw KnoxCryptException(KnoxCryptError::FolderNotEmpty); } } try { parentEntry->removeFolder(boostPath.filename().string()); } catch (...) { throw KnoxCryptException(KnoxCryptError::NotFound); } // also remove entry and its parent from parent cache this->removeFolderFromCache(boostPath); this->removeFolderFromCache(boostPath.parent_path()); // need to also check if this now f***s up the cached file resetCachedFile(thePath); }
void create_directories(std::string const& f, error_code& ec) { ec.clear(); if (is_directory(f, ec)) return; if (ec != boost::system::errc::no_such_file_or_directory) return; ec.clear(); if (is_root_path(f)) return; if (has_parent_path(f)) { create_directories(parent_path(f), ec); if (ec) return; } create_directory(f, ec); }
/** * @brief Creates specified directory * * Function creates given directory recursively. * * @param dirName Directory name to created. * * @exception std::runtime_error Operation did not succeed */ void condor2nav::DirectoryCreate(const bfs::path &dirName) { bool activeSync = false; const std::string str = dirName.string(); if(str.size() > 2 && str[0] == '\\' && str[1] != '\\') activeSync = true; if(!dirName.empty()) { if(!activeSync) { bfs::create_directories(dirName); } else { auto path = dirName; std::vector<bfs::path> dirs; while(path.parent_path() != "\\") { dirs.emplace_back(path); path = path.parent_path(); } auto &activeSync = CActiveSync::Instance(); std::for_each(dirs.crbegin(), dirs.crend(), [&](const bfs::path &d){ activeSync.DirectoryCreate(d); }); } } }
void posix_storage::rename_file(file_index_t const index, std::string const& new_filename, storage_error& ec) { if (index < file_index_t(0) || index >= files().end_file()) return; std::string const old_name = files().file_path(index, m_save_path); if (exists(old_name, ec.ec)) { std::string new_path; if (is_complete(new_filename)) new_path = new_filename; else new_path = combine_path(m_save_path, new_filename); std::string new_dir = parent_path(new_path); // create any missing directories that the new filename // lands in create_directories(new_dir, ec.ec); if (ec.ec) { ec.file(index); ec.operation = operation_t::file_rename; return; } rename(old_name, new_path, ec.ec); if (ec.ec == boost::system::errc::no_such_file_or_directory) ec.ec.clear(); if (ec) { ec.file(index); ec.operation = operation_t::file_rename; return; } } else if (ec.ec) { // if exists fails, report that error ec.file(index); ec.operation = operation_t::file_rename; return; } if (!m_mapped_files) { m_mapped_files.reset(new file_storage(files())); } m_mapped_files->rename_file(index, new_filename); }
/// @brief Generates an unique name for the ffms2 index file and prepares the cache folder if it doesn't exist /// @param filename The name of the source file /// @return Returns the generated filename. agi::fs::path FFmpegSourceProvider::GetCacheFilename(agi::fs::path const& filename) { // Get the size of the file to be hashed uintmax_t len = agi::fs::Size(filename); // Get the hash of the filename boost::crc_32_type hash; hash.process_bytes(filename.string().c_str(), filename.string().size()); // Generate the filename auto result = config::path->Decode("?local/ffms2cache/" + std::to_string(hash.checksum()) + "_" + std::to_string(len) + "_" + std::to_string(agi::fs::ModifiedTime(filename)) + ".ffindex"); // Ensure that folder exists agi::fs::CreateDirectory(result.parent_path()); return result; }
int ppfs_unlink (const char *path){ fprintf(stderr, "ppfs_unlink path : %s\n", path); ppacket* p = createpacket_s(4+strlen(path),CLTOMD_UNLINK,-1); uint8_t* ptr = p->startptr + HEADER_LEN; put32bit(&ptr,strlen(path)); memcpy(ptr,path,strlen(path)); ptr += strlen(path); sendpacket(fd,p); free(p); p = receivepacket(fd); const uint8_t* ptr2 = p->startptr; int status = get32bit(&ptr2); fprintf(stderr, "unlink status:%d\n", status); if(status == 0){ attr_cache* ac; chunk_cache* cc; if(lookup_attr_cache(path,&ac) == 0){ remove_attr_cache(ac); free_attr_cache(ac); } if(lookup_chunk_cache(path,&cc) == 0){ remove_chunk_cache(cc); free_chunk_cache(cc); } dir_cache* dc; char* ppath = parent_path(path); fprintf(stderr,"/n/n/npath=%s,parent_path:%s\n\n\n",path,ppath); if(lookup_dir_cache(ppath,&dc) == 0){ remove_dir_cache(dc); free_dir_cache(dc); } free(ppath); } free(p); return status; }
void CoreFS::resetCachedFile(::boost::filesystem::path const &thePath) { if(m_cachedFileAndPath) { auto cachedPath = boost::filesystem::path(m_cachedFileAndPath->first); auto boostFolderPath = thePath; do { cachedPath = cachedPath.parent_path(); if(cachedPath == boostFolderPath) { m_cachedFileAndPath.reset(); m_cachedFileAndPath = nullptr; break; } } while (cachedPath.has_parent_path()); } }
PathObjectList get_objects(const hdf5::node::Group &base,const Path &path) { PathObjectList list; if(path.has_attribute()) { //if we are looking for attributes we first have to identify the parent //objects. NodeList parent_list; if(path.size()==0) { parent_list.push_back(base); } else { Path parent_path(path); parent_path.attribute(std::string()); parent_list = get_objects(base,parent_path); } //once we have identified the parents we can select those who have //an attribute of appropriate name for(auto node: parent_list) { if(node.attributes.exists(path.attribute())) list.push_back(node.attributes[path.attribute()]); } } else { auto iter_begin = hdf5::node::RecursiveLinkIterator::begin(base); auto iter_end = hdf5::node::RecursiveLinkIterator::end(base); if(is_absolute(path)) std::copy_if(iter_begin,iter_end,std::back_inserter(list),AbsolutePathMatcher(path)); else { std::copy_if(iter_begin,iter_end,std::back_inserter(list),RelativePathMatcher(path,get_path(base))); } } return list; }
bool WatcherRunner::createExtension(const std::string& extension) { { WatcherLocker locker; if (Watcher::getState(extension).last_respawn_time > getUnixTime() - getWorkerLimit(RESPAWN_LIMIT)) { LOG(WARNING) << "Extension respawning too quickly: " << extension; // Unlike a worker, if an extension respawns to quickly we give up. return false; } } // Check the path to the previously-discovered extension binary. boost::system::error_code ec; auto exec_path = fs::system_complete(fs::path(extension), ec); if (!safePermissions( exec_path.parent_path().string(), exec_path.string(), true)) { // Extension binary has become unsafe. LOG(WARNING) << RLOG(1382) << "Extension binary has unsafe permissions: " << extension; return false; } auto ext_process = PlatformProcess::launchExtension(exec_path.string(), extension, Flag::getValue("extensions_socket"), Flag::getValue("extensions_timeout"), Flag::getValue("extensions_interval"), Flag::getValue("verbose")); if (ext_process == nullptr) { // Unrecoverable error, cannot create an extension process. LOG(ERROR) << "Cannot create extension process: " << extension; Initializer::shutdown(EXIT_FAILURE); } Watcher::setExtension(extension, ext_process); Watcher::resetExtensionCounters(extension, getUnixTime()); VLOG(1) << "Created and monitoring extension child (" << ext_process->pid() << "): " << extension; return true; }
/// removes '.' and '..' bits /// from http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem boost::filesystem::path normalize(const boost::filesystem::path &path) { auto absPath = boost::filesystem::absolute(path); auto it = absPath.begin(); auto result = *it++; // For the rest remove ".." and "." in a path with no symlinks for (; it != absPath.end(); ++it) { // Just move back on ../ if (*it == "..") { result = result.parent_path(); } // Ignore "." else if (*it != ".") { // Just cat other path entries result /= *it; } } return result; }
void INotifyEventPublisher::configure() { for (auto& sub : subscriptions_) { // Anytime a configure is called, try to monitor all subscriptions. // Configure is called as a response to removing/adding subscriptions. // This means recalculating all monitored paths. auto sc = getSubscriptionContext(sub->context); if (sc->discovered_.size() > 0) { continue; } sc->discovered_ = sc->path; if (sc->path.find("**") != std::string::npos) { sc->recursive = true; sc->discovered_ = sc->path.substr(0, sc->path.find("**")); sc->path = sc->discovered_; } if (sc->path.find('*') != std::string::npos) { // If the wildcard exists within the file (leaf), remove and monitor the // directory instead. Apply a fnmatch on fired events to filter leafs. auto fullpath = fs::path(sc->path); if (fullpath.filename().string().find('*') != std::string::npos) { sc->discovered_ = fullpath.parent_path().string(); } if (sc->discovered_.find('*') != std::string::npos) { // If a wildcard exists within the tree (stem), resolve at configure // time and monitor each path. std::vector<std::string> paths; resolveFilePattern(sc->discovered_, paths); for (const auto& _path : paths) { addMonitor(_path, sc->recursive); } sc->recursive_match = sc->recursive; continue; } } addMonitor(sc->discovered_, sc->recursive); } }
void searchDir(const string & search_dir, vector<string> & searched_file) { boost::filesystem::path parent_path(search_dir); if (!boost::filesystem::is_directory(parent_path)) { return ; } boost::filesystem::directory_iterator end_it; for (boost::filesystem::directory_iterator it(parent_path); it != end_it; ++it) { boost::filesystem::path seached_path = *it; if (boost::filesystem::is_directory(seached_path)) { string file_dir = seached_path.leaf().string(); if ((file_dir != ".") && (file_dir != "..")) { searched_file.push_back(it->path().filename().string()); } } } }
int ppfs_create(const char *path, mode_t mt, struct fuse_file_info *fi){ fprintf(stderr, "\n\n\n\nppfs_create path : %s\n", path); fprintf(stderr, "ppfs_create mode : %o\n\n\n\n\n", mt); ppacket* p = createpacket_s(4+strlen(path)+4,CLTOMD_CREATE,-1); uint8_t* ptr = p->startptr + HEADER_LEN; mt = (mt & 0777) | S_IFREG; put32bit(&ptr,strlen(path)); memcpy(ptr,path,strlen(path)); ptr += strlen(path); put32bit(&ptr,mt); sendpacket(fd,p); free(p); p = receivepacket(fd); const uint8_t* ptr2 = p->startptr; int status = get32bit(&ptr2); fprintf(stderr, "create status:%d\n", status); free(p); if(status == 0){ dir_cache* dc; char* ppath = parent_path(path); fprintf(stderr,"/n/n/npath=%s,parent_path:%s\n\n\n",path,ppath); if(lookup_dir_cache(ppath,&dc) == 0){ remove_dir_cache(dc); free_dir_cache(dc); } free(ppath); } return status; }
boost::filesystem::path get_relative(const boost::filesystem::path& file, const boost::filesystem::path& relative_to) { auto result = file.filename(); auto current_path = file; if (boost::filesystem::equivalent(current_path, relative_to)) return L""; while (true) { current_path = current_path.parent_path(); if (boost::filesystem::equivalent(current_path, relative_to)) break; if (current_path.empty()) CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("File " + file.string() + " not relative to folder " + relative_to.string())); result = current_path.filename() / result; } return result; }
void UserConfig::try_write_data(Files::Filesystem& fs) const { try { auto config_path = get_config_path(); auto config_dir = config_path.parent_path(); std::error_code ec; fs.create_directory(config_dir, ec); fs.write_contents(config_path, Strings::format("User-Id: %s\n" "User-Since: %s\n" "Mac-Hash: %s\n" "Survey-Completed: %s\n", user_id, user_time, user_mac, last_completed_survey), ec); } catch (...) { } }