Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
fs Namespace Reference

Classes

struct  DirListNode
 

Functions

std::vector< DirListNodeGetDirListing (const std::string &pathstring)
 
bool CreateDir (const std::string &path)
 
bool PathExists (const std::string &path)
 
bool IsPathAbsolute (const std::string &path)
 
bool IsDir (const std::string &path)
 
bool IsExecutable (const std::string &path)
 
bool IsDirDelimiter (char c)
 
bool RecursiveDelete (const std::string &path)
 
bool DeleteSingleFileOrEmptyDirectory (const std::string &path)
 
std::string TempPath ()
 Returns path to temp directory.
 
std::string CreateTempFile ()
 Returns path to securely-created temporary file (will already exist when this function returns).
 
std::string CreateTempDir ()
 Returns path to securely-created temporary directory (will already exist when this function returns).
 
bool CopyFileContents (const std::string &source, const std::string &target)
 
void GetRecursiveDirs (std::vector< std::string > &dirs, const std::string &dir)
 
std::vector< std::string > GetRecursiveDirs (const std::string &dir)
 
void GetRecursiveSubPaths (const std::string &path, std::vector< std::string > &dst, bool list_files, const std::set< char > &ignore)
 
bool RecursiveDeleteContent (const std::string &path)
 
bool CreateAllDirs (const std::string &path)
 
bool CopyDir (const std::string &source, const std::string &target)
 
bool MoveDir (const std::string &source, const std::string &target)
 
bool PathStartsWith (const std::string &path, const std::string &prefix)
 
std::string RemoveLastPathComponent (const std::string &path, std::string *removed, int count)
 
std::string RemoveRelativePathComponents (std::string path)
 
std::string AbsolutePath (const std::string &path)
 
const char * GetFilenameFromPath (const char *path)
 
bool safeWriteToFile (const std::string &path, std::string_view content)
 
bool ReadFile (const std::string &path, std::string &out, bool log_error)
 
bool Rename (const std::string &from, const std::string &to)
 
bool OpenStream (std::filebuf &stream, const char *filename, std::ios::openmode mode, bool log_error, bool log_warn)
 Open a file buffer with error handling, commonly used with std::fstream.rdbuf().
 
bool IsFile (const std::string &path)
 

Function Documentation

◆ AbsolutePath()

std::string fs::AbsolutePath ( const std::string & path)

Referenced by ScriptApiSecurity::checkPath(), ScriptApiSecurity::checkPathWithGamedef(), findSubgame(), and ModApiMainMenu::l_get_modpaths().

+ Here is the caller graph for this function:

◆ CopyDir()

bool fs::CopyDir ( const std::string & source,
const std::string & target )

References CopyDir(), CopyFileContents(), CreateAllDirs(), DIR_DELIM, GetDirListing(), and PathExists().

Referenced by CopyDir(), ModApiMainMenu::l_copy_dir(), ModApiUtil::l_cpdir(), and MoveDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CopyFileContents()

bool fs::CopyFileContents ( const std::string & source,
const std::string & target )

References errorstream, and tracestream.

Referenced by CopyDir(), TestFileSys::testCopyFileContents(), and FileCache::updateCopyFile().

+ Here is the caller graph for this function:

◆ CreateAllDirs()

bool fs::CreateAllDirs ( const std::string & path)

References CreateDir(), PathExists(), and RemoveLastPathComponent().

Referenced by CopyDir(), create_userdata_path(), porting::createCacheDirTag(), FileCache::createDir(), ModStorageDatabaseFiles::endSave(), Client::initLocalMapSaving(), ModApiMainMenu::l_create_dir(), ModApiServer::l_get_mod_data_path(), ModApiUtil::l_mkdir(), loadGameConfAndInitWorld(), Database_SQLite3::openDatabase(), TestServerModManager::runTests(), and MapSettingsManager::saveMapMeta().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateDir()

bool fs::CreateDir ( const std::string & path)

Referenced by PlayerDatabaseFiles::PlayerDatabaseFiles(), Server::Server(), create_userdata_path(), CreateAllDirs(), Client::makeScreenshot(), ServerEnvironment::migratePlayersDatabase(), TestServerModManager::runTests(), PlayerDatabaseFiles::savePlayer(), and TestFileSys::testRecursiveDelete().

+ Here is the caller graph for this function:

◆ CreateTempDir()

std::string fs::CreateTempDir ( )

Returns path to securely-created temporary directory (will already exist when this function returns).

Returns
path or "" on error

References DIR_DELIM, and TempPath().

Referenced by TestBase::getTestTempDirectory(), and ModApiMainMenu::l_get_temp_path().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateTempFile()

std::string fs::CreateTempFile ( )

Returns path to securely-created temporary file (will already exist when this function returns).

Returns
path or "" on error

References DIR_DELIM, and TempPath().

Referenced by ModApiMainMenu::l_get_temp_path().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeleteSingleFileOrEmptyDirectory()

bool fs::DeleteSingleFileOrEmptyDirectory ( const std::string & path)

References errorstream, and IsDir().

Referenced by Server::~Server(), GUIEngine::downloadFile(), ModApiUtil::l_rmdir(), ServerEnvironment::migratePlayersDatabase(), TestBan::reinitTestEnv(), PlayerDatabaseFiles::removePlayer(), TestAuthDatabase::runTests(), TestModStorageDatabase::runTests(), FileLogOutput::setFile(), Server::stepPendingDynMediaCallbacks(), and TestFileSys::testNonExist().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetDirListing()

std::vector< DirListNode > fs::GetDirListing ( const std::string & pathstring)

◆ GetFilenameFromPath()

const char * fs::GetFilenameFromPath ( const char * path)

References DIR_DELIM_CHAR.

Referenced by ScriptApiSecurity::checkPathWithGamedef(), Server::dynamicAddMedia(), GUIEngine::getContentTranslations(), Server::init(), ModApiMainMenu::l_check_mod_configuration(), main(), and parseContentInfo().

+ Here is the caller graph for this function:

◆ GetRecursiveDirs() [1/2]

std::vector< std::string > fs::GetRecursiveDirs ( const std::string & dir)

References dir(), and GetRecursiveDirs().

+ Here is the call graph for this function:

◆ GetRecursiveDirs() [2/2]

void fs::GetRecursiveDirs ( std::vector< std::string > & dirs,
const std::string & dir )

References dir(), GetRecursiveSubPaths(), and IsDir().

Referenced by Server::fillMediaCache(), ServerModManager::getModsMediaPaths(), GetRecursiveDirs(), getTextureDirs(), and Server::init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRecursiveSubPaths()

void fs::GetRecursiveSubPaths ( const std::string & path,
std::vector< std::string > & dst,
bool list_files,
const std::set< char > & ignore )

References DIR_DELIM, GetDirListing(), and GetRecursiveSubPaths().

Referenced by GetRecursiveDirs(), and GetRecursiveSubPaths().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsDir()

bool fs::IsDir ( const std::string & path)

Referenced by DeleteSingleFileOrEmptyDirectory(), ModStorageDatabaseFiles::endSave(), GetRecursiveDirs(), Client::initLocalMapSaving(), IsFile(), ModApiMainMenu::l_is_dir(), Client::migrateModStorage(), porting::open_directory(), TestFileSys::testNonExist(), and TestFileSys::testRecursiveDelete().

+ Here is the caller graph for this function:

◆ IsDirDelimiter()

bool fs::IsDirDelimiter ( char c)

Referenced by PathStartsWith(), RemoveLastPathComponent(), RemoveRelativePathComponents(), and TestFileSys::testIsDirDelimiter().

+ Here is the caller graph for this function:

◆ IsExecutable()

bool fs::IsExecutable ( const std::string & path)

Referenced by TestFileSys::testNonExist().

+ Here is the caller graph for this function:

◆ IsFile()

bool fs::IsFile ( const std::string & path)
inline

References IsDir(), and PathExists().

Referenced by getContentType(), sound::OpenALSoundManager::loadSoundFile(), sound::ProxySoundManager::loadSoundFile(), parseModContents(), TestBan::testCreate(), TestFileSys::testNonExist(), and TestFileSys::testRecursiveDelete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsPathAbsolute()

bool fs::IsPathAbsolute ( const std::string & path)

Referenced by load_schematic(), Client::makeScreenshot(), and RecursiveDelete().

+ Here is the caller graph for this function:

◆ MoveDir()

bool fs::MoveDir ( const std::string & source,
const std::string & target )

References CopyDir(), errorstream, infostream, PathExists(), RecursiveDelete(), and Rename().

Referenced by ModApiMainMenu::l_copy_dir(), and ModApiUtil::l_mvdir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OpenStream()

bool fs::OpenStream ( std::filebuf & stream,
const char * filename,
std::ios::openmode mode,
bool log_error,
bool log_warn )

Open a file buffer with error handling, commonly used with std::fstream.rdbuf().

Parameters
streamstream references, must not already be open
filenamefilename to open
modemode bits (used as-is)
log_errorlog failure to errorstream?
log_warnlog failure to warningstream?
Returns
true if success

References errorstream, LAST_OS_ERROR, and warningstream.

Referenced by open_ifstream(), open_ofstream(), FileLogOutput::setFile(), and TestFileSys::testNonExist().

+ Here is the caller graph for this function:

◆ PathExists()

◆ PathStartsWith()

bool fs::PathStartsWith ( const std::string & path,
const std::string & prefix )

References FILESYS_CASE_INSENSITIVE, IsDirDelimiter(), and my_tolower().

Referenced by ScriptApiSecurity::checkPathWithGamedef(), MainMenuScripting::mayModifyPath(), and TestFileSys::testPathStartsWith().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadFile()

bool fs::ReadFile ( const std::string & path,
std::string & out,
bool log_error )

References open_ifstream().

Referenced by Server::addMediaFile(), GUIEngine::getContentTranslations(), Server::getTranslationLanguage(), parseContentInfo(), parseModContents(), read_translation_file(), SourceShaderCache::readFile(), ShadowRenderer::readShaderFile(), Client::scanModSubfolder(), Server::sendRequestedMedia(), TestFileSys::testCopyFileContents(), TestMapSettingsManager::testMapSettingsManager(), TestFileSys::testNonExist(), and TestFileSys::testSafeWriteToFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RecursiveDelete()

bool fs::RecursiveDelete ( const std::string & path)

References errorstream, infostream, and IsPathAbsolute().

Referenced by ModApiMainMenu::l_delete_dir(), ModApiMainMenu::l_delete_world(), ModApiUtil::l_rmdir(), porting::migrateCachePath(), MoveDir(), RecursiveDeleteContent(), TestModStorageDatabase::runTests(), TestBase::testModule(), and TestFileSys::testRecursiveDelete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RecursiveDeleteContent()

bool fs::RecursiveDeleteContent ( const std::string & path)

References DIR_DELIM, errorstream, GetDirListing(), infostream, RecursiveDelete(), and trim().

+ Here is the call graph for this function:

◆ RemoveLastPathComponent()

std::string fs::RemoveLastPathComponent ( const std::string & path,
std::string * removed,
int count )

References DIR_DELIM, and IsDirDelimiter().

Referenced by ScriptApiSecurity::checkPath(), CreateAllDirs(), MapSettingsManager::saveMapMeta(), TestFileSys::testRemoveLastPathComponent(), and TestFileSys::testRemoveLastPathComponentWithTrailingDelimiter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveRelativePathComponents()

std::string fs::RemoveRelativePathComponents ( std::string path)

References DIR_DELIM, and IsDirDelimiter().

Referenced by ModApiMainMenu::l_get_cache_path(), ModApiMainMenu::l_get_clientmodpath(), ModApiMainMenu::l_get_gamepath(), ModApiMainMenu::l_get_modpath(), ModApiMainMenu::l_get_modpaths(), ModApiMainMenu::l_get_texturepath(), ModApiMainMenu::l_get_texturepath_share(), ModApiMainMenu::l_get_user_path(), MainMenuScripting::mayModifyPath(), and TestFileSys::testRemoveRelativePathComponent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Rename()

bool fs::Rename ( const std::string & from,
const std::string & to )

Referenced by ServerEnvironment::migrateAuthDatabase(), porting::migrateCachePath(), Client::migrateModStorage(), Server::migrateModStorageDatabase(), ServerEnvironment::migratePlayersDatabase(), MoveDir(), FileLogOutput::setFile(), and TestFileSys::testNonExist().

+ Here is the caller graph for this function:

◆ safeWriteToFile()

bool fs::safeWriteToFile ( const std::string & path,
std::string_view content )

References errorstream, itos(), LAST_OS_ERROR, open_ofstream(), remove(), and sleep_ms.

Referenced by ModStorageDatabaseFiles::endSave(), ModApiUtil::l_safe_file_write(), LuaAreaStore::l_to_file(), BanManager::save(), ServerEnvironment::saveMeta(), PlayerDatabaseFiles::savePlayer(), Schematic::saveSchematicToFile(), TestFileSys::testSafeWriteToFile(), Settings::updateConfigFile(), and AuthDatabaseFiles::writeAuthFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TempPath()

std::string fs::TempPath ( )

Returns path to temp directory.

You probably don't want to use this directly, see CreateTempFile or CreateTempDir.

Returns
path or "" on error

References DIR_DELIM, and porting::path_cache.

Referenced by CreateTempDir(), CreateTempFile(), and MainMenuScripting::mayModifyPath().

+ Here is the caller graph for this function: