Error UserSettings::initialize() { // calculate settings file path FilePath settingsDir = module_context::registerMonitoredUserScratchDir( "user-settings", boost::bind(&UserSettings::onSettingsFileChanged, this, _1)); settingsFilePath_ = settingsDir.complete("user-settings"); // if it doesn't exist see if we can migrate an old user settings if (!settingsFilePath_.exists()) { FilePath oldSettingsPath = module_context::userScratchPath().complete("user-settings"); if (oldSettingsPath.exists()) oldSettingsPath.move(settingsFilePath_); } // read the settings Error error = settings_.initialize(settingsFilePath_); if (error) return error; // make sure we have a context id if (contextId().empty()) setContextId(core::system::generateUuid()); return Success(); }
// IN: String path, String targetPath core::Error renameFile(const core::json::JsonRpcRequest& request, json::JsonRpcResponse* pResponse) { // read params std::string path, targetPath; Error error = json::readParams(request.params, &path, &targetPath); if (error) return error ; // if the destination already exists then send back file exists FilePath destPath = module_context::resolveAliasedPath(targetPath) ; if (destPath.exists()) return fileExistsError(ERROR_LOCATION); // create file info now before we remove FilePath sourcePath = module_context::resolveAliasedPath(path); FileInfo sourceFileInfo(sourcePath); // move the file Error renameError = sourcePath.move(destPath); if (renameError) return renameError ; // generate delete event for folders (inotify doesn't do this right now) if (sourceFileInfo.isDirectory()) enqueFileRemovedEvent(sourceFileInfo); return Success() ; }
// IN: String path, String targetPath core::Error renameFile(const core::json::JsonRpcRequest& request, json::JsonRpcResponse* pResponse) { // read params std::string path, targetPath; Error error = json::readParams(request.params, &path, &targetPath); if (error) return error ; // if the destination already exists then send back file exists FilePath destPath = module_context::resolveAliasedPath(targetPath) ; if (destPath.exists()) return fileExistsError(ERROR_LOCATION); // move the file FilePath sourcePath = module_context::resolveAliasedPath(path); Error renameError = sourcePath.move(destPath); if (renameError) return renameError ; // propagate rename to source database (non fatal if this fails) error = source_database::rename(sourcePath, destPath); if (error) LOG_ERROR(error); return Success() ; }
Error createSessionDirFromOldSourceDatabase(FilePath* pSessionDir) { // move properties (if any) into new source database root FilePath propsPath = oldSourceDatabaseRoot().complete("properties"); if (propsPath.exists()) { FilePath newPropsPath = sourceDatabaseRoot().complete("prop"); Error error = propsPath.move(newPropsPath); if (error) LOG_ERROR(error); } // move the old source database into a new dir *pSessionDir = generateSessionDirPath(); Error error = oldSourceDatabaseRoot().move(*pSessionDir); if (error) LOG_ERROR(error); // if that failed we might still need to call ensureDirectory error = pSessionDir->ensureDirectory(); if (error) return error; // attempt to acquire the lock. if we can't then we still continue // so we can support filesystems that don't have file locks. error = sessionDirLock().acquire(sessionLockFilePath(*pSessionDir)); if (error) LOG_ERROR(error); return Success(); }
Error createStandalonePresentation(const json::JsonRpcRequest& request, json::JsonRpcResponse* pResponse) { std::string pathParam; Error error = json::readParam(request.params, 0, &pathParam); if (error) return error; FilePath targetPath = module_context::resolveAliasedPath(pathParam); FilePath htmlFilePath = presentation::state::htmlFilePath(); ErrorResponse errorResponse; if (!savePresentationAsStandalone(htmlFilePath, &errorResponse)) { pResponse->setError(systemError(boost::system::errc::io_error, ERROR_LOCATION), json::toJsonString(errorResponse.message)); } return htmlFilePath.move(targetPath); }