Ring Daemon
Loading...
Searching...
No Matches
jami::fileutils Namespace Reference

Classes

struct  ArchiveStorageData
 

Functions

int accessFile (const std::string &file, int mode)
 Windows compatibility wrapper for checking read-only attribute.
 
bool createFileLink (const std::filesystem::path &linkFile, const std::filesystem::path &target, bool hard)
 
bool createHardlink (const std::filesystem::path &linkFile, const std::filesystem::path &target)
 
bool createSymlink (const std::filesystem::path &linkFile, const std::filesystem::path &target)
 
bool eraseFile (const std::string &path, bool dosync)
 
bool eraseFile_posix (const std::string &path, bool dosync)
 
std::string expand_path (const std::string &path)
 Expand the given path.
 
const std::filesystem::path & get_cache_dir ()
 
std::filesystem::path get_cache_dir (const char *pkg)
 
const std::filesystem::path & get_config_dir ()
 
std::filesystem::path get_config_dir (const char *pkg)
 
const std::filesystem::path & get_data_dir ()
 
std::filesystem::path get_data_dir (const char *pkg)
 
const std::filesystem::path & get_home_dir ()
 
std::filesystem::path get_home_dir_impl ()
 
const std::filesystem::path & get_resource_dir_path ()
 Get the resource directory path that was set with set_resource_dir_path.
 
std::string getCleanPath (const std::string &base, const std::string &path)
 If path is contained in base, return the suffix, otherwise return the full path.
 
std::string_view getFileExtension (std::string_view filename)
 
std::filesystem::path getFullPath (const std::filesystem::path &base, const std::filesystem::path &path)
 If path is relative, it is appended to base.
 
std::string getOrCreateLocalDeviceId ()
 
bool isDirectoryWritable (const std::string &directory)
 
bool isPathRelative (const std::filesystem::path &path)
 
uint64_t lastWriteTimeInSeconds (const std::filesystem::path &filePath)
 Return the last write time (epoch time) of a given file path (in seconds).
 
std::vector< uint8_tloadCacheFile (const std::filesystem::path &path, std::chrono::system_clock::duration maxAge)
 
std::string loadCacheTextFile (const std::filesystem::path &path, std::chrono::system_clock::duration maxAge)
 
std::vector< uint8_tloadFile (const std::filesystem::path &path, const std::filesystem::path &default_dir={})
 Read the full content of a file at path.
 
std::string loadTextFile (const std::filesystem::path &path, const std::filesystem::path &default_dir)
 
ArchiveStorageData readArchive (const std::filesystem::path &path, std::string_view scheme, const std::string &pwd)
 
int remove (const std::filesystem::path &path, bool erase)
 
void saveFile (const std::filesystem::path &path, const std::vector< uint8_t > &data, mode_t mode=0644)
 
void saveFile (const std::filesystem::path &path, const uint8_t *data, size_t data_size, mode_t mode=0644)
 
void saveFile (const std::filesystem::path &path, const uint8_t *data, size_t data_size, mode_t UNUSED mode)
 
void set_resource_dir_path (const std::filesystem::path &resourceDirPath)
 Set the program's resource directory path.
 
std::string sha3File (const std::filesystem::path &path)
 
std::string sha3sum (const std::vector< uint8_t > &buffer)
 
bool writeArchive (const std::string &archive_str, const std::filesystem::path &path, std::string_view scheme, const std::string &password, const std::vector< uint8_t > &password_salt)
 

Variables

static constexpr auto ARCHIVE_AUTH_SCHEME_KEY = "key"sv
 
static constexpr auto ARCHIVE_AUTH_SCHEME_NONE = ""sv
 
static constexpr auto ARCHIVE_AUTH_SCHEME_PASSWORD = "password"sv
 
static std::filesystem::path resource_dir_path
 

Function Documentation

◆ accessFile()

int jami::fileutils::accessFile ( const std::string &  file,
int  mode 
)

Windows compatibility wrapper for checking read-only attribute.

Definition at line 805 of file fileutils.cpp.

References jami::emitSignal().

Referenced by isDirectoryWritable().

Here is the call graph for this function:

◆ createFileLink()

bool jami::fileutils::createFileLink ( const std::filesystem::path &  linkFile,
const std::filesystem::path &  target,
bool  hard 
)

Definition at line 216 of file fileutils.cpp.

References createHardlink(), createSymlink(), jami::emitSignal(), and JAMI_DEBUG.

Referenced by jami::vCard::utils::save().

Here is the call graph for this function:

◆ createHardlink()

bool jami::fileutils::createHardlink ( const std::filesystem::path &  linkFile,
const std::filesystem::path &  target 
)

Definition at line 202 of file fileutils.cpp.

References jami::emitSignal(), JAMI_LOG, and JAMI_WARNING.

Referenced by createFileLink().

Here is the call graph for this function:

◆ createSymlink()

bool jami::fileutils::createSymlink ( const std::filesystem::path &  linkFile,
const std::filesystem::path &  target 
)

Definition at line 188 of file fileutils.cpp.

References jami::emitSignal(), JAMI_LOG, and JAMI_WARNING.

Referenced by createFileLink().

Here is the call graph for this function:

◆ eraseFile()

bool jami::fileutils::eraseFile ( const std::string &  path,
bool  dosync 
)

Definition at line 734 of file fileutils.cpp.

References jami::emitSignal(), and eraseFile_posix().

Referenced by remove().

Here is the call graph for this function:

◆ eraseFile_posix()

bool jami::fileutils::eraseFile_posix ( const std::string &  path,
bool  dosync 
)

Definition at line 690 of file fileutils.cpp.

References jami::emitSignal(), JAMI_WARN, JAMI_WARNING, S_IWGRP, and S_IWUSR.

Referenced by eraseFile().

Here is the call graph for this function:

◆ expand_path()

std::string jami::fileutils::expand_path ( const std::string &  path)

Expand the given path.

Parameters
pathThe path to be expanded.
Returns
The expanded path as a string.

Definition at line 139 of file fileutils.cpp.

References jami::emitSignal(), and JAMI_ERR.

Referenced by jami::AudioPreference::setRecordPath().

Here is the call graph for this function:

◆ get_cache_dir() [1/2]

const std::filesystem::path & jami::fileutils::get_cache_dir ( )

◆ get_cache_dir() [2/2]

std::filesystem::path jami::fileutils::get_cache_dir ( const char pkg)

Definition at line 469 of file fileutils.cpp.

References jami::emitSignal(), get_home_dir(), jami::to_string(), and XDG_CACHE_HOME.

Here is the call graph for this function:

◆ get_config_dir() [1/2]

const std::filesystem::path & jami::fileutils::get_config_dir ( )

Definition at line 619 of file fileutils.cpp.

References jami::emitSignal(), and get_config_dir().

Referenced by get_config_dir(), jami::Manager::init(), jami::MediaEncoder::readConfig(), and jami::Manager::ManagerPimpl::retrieveConfigPath().

Here is the call graph for this function:

◆ get_config_dir() [2/2]

std::filesystem::path jami::fileutils::get_config_dir ( const char pkg)

Definition at line 584 of file fileutils.cpp.

References jami::emitSignal(), get_home_dir(), JAMI_DBG, and XDG_CONFIG_HOME.

Here is the call graph for this function:

◆ get_data_dir() [1/2]

◆ get_data_dir() [2/2]

std::filesystem::path jami::fileutils::get_data_dir ( const char pkg)

Definition at line 545 of file fileutils.cpp.

References jami::emitSignal(), get_home_dir(), and XDG_DATA_HOME.

Here is the call graph for this function:

◆ get_home_dir()

const std::filesystem::path & jami::fileutils::get_home_dir ( )

Definition at line 538 of file fileutils.cpp.

References jami::emitSignal(), and get_home_dir_impl().

Referenced by get_cache_dir(), get_config_dir(), get_data_dir(), and jami::Recordable::toggleRecording().

Here is the call graph for this function:

◆ get_home_dir_impl()

std::filesystem::path jami::fileutils::get_home_dir_impl ( )

Definition at line 502 of file fileutils.cpp.

References jami::emitSignal(), PROTECTED_GETENV, and jami::to_string().

Referenced by get_home_dir().

Here is the call graph for this function:

◆ get_resource_dir_path()

const std::filesystem::path & jami::fileutils::get_resource_dir_path ( )

Get the resource directory path that was set with set_resource_dir_path.

Returns
The resource directory path.

Definition at line 132 of file fileutils.cpp.

References jami::emitSignal(), and resource_dir_path.

Referenced by jami::Account::loadConfig().

Here is the call graph for this function:

◆ getCleanPath()

std::string jami::fileutils::getCleanPath ( const std::string &  base,
const std::string &  path 
)

If path is contained in base, return the suffix, otherwise return the full path.

Parameters
basemust not finish with DIR_SEPARATOR_STR, can be empty
paththe path

Definition at line 262 of file fileutils.cpp.

References DIR_SEPARATOR_STR, and jami::emitSignal().

Here is the call graph for this function:

◆ getFileExtension()

std::string_view jami::fileutils::getFileExtension ( std::string_view  filename)

Definition at line 244 of file fileutils.cpp.

References jami::emitSignal().

Referenced by jami::getFileId().

Here is the call graph for this function:

◆ getFullPath()

std::filesystem::path jami::fileutils::getFullPath ( const std::filesystem::path &  base,
const std::filesystem::path &  path 
)

◆ getOrCreateLocalDeviceId()

std::string jami::fileutils::getOrCreateLocalDeviceId ( )

Definition at line 827 of file fileutils.cpp.

References jami::emitSignal(), get_data_dir(), JAMI_ERROR, and jami::to_hex_string().

Referenced by jami::Manager::init().

Here is the call graph for this function:

◆ isDirectoryWritable()

bool jami::fileutils::isDirectoryWritable ( const std::string &  directory)

Definition at line 182 of file fileutils.cpp.

References accessFile(), and jami::emitSignal().

Referenced by jami::AudioPreference::setRecordPath().

Here is the call graph for this function:

◆ isPathRelative()

bool jami::fileutils::isPathRelative ( const std::filesystem::path &  path)

Definition at line 256 of file fileutils.cpp.

References jami::emitSignal().

Referenced by getFullPath().

Here is the call graph for this function:

◆ lastWriteTimeInSeconds()

uint64_t jami::fileutils::lastWriteTimeInSeconds ( const std::filesystem::path &  filePath)

Return the last write time (epoch time) of a given file path (in seconds).

Definition at line 815 of file fileutils.cpp.

References jami::emitSignal(), and JAMI_WARNING.

Referenced by jami::Conversation::preferences(), and jami::Conversation::updatePreferences().

Here is the call graph for this function:

◆ loadCacheFile()

std::vector< uint8_t > jami::fileutils::loadCacheFile ( const std::filesystem::path &  path,
std::chrono::system_clock::duration  maxAge 
)

Definition at line 330 of file fileutils.cpp.

References jami::emitSignal(), and JAMI_LOG.

Here is the call graph for this function:

◆ loadCacheTextFile()

std::string jami::fileutils::loadCacheTextFile ( const std::filesystem::path &  path,
std::chrono::system_clock::duration  maxAge 
)

Definition at line 346 of file fileutils.cpp.

References jami::emitSignal(), JAMI_LOG, and loadTextFile().

Here is the call graph for this function:

◆ loadFile()

◆ loadTextFile()

std::string jami::fileutils::loadTextFile ( const std::filesystem::path &  path,
const std::filesystem::path &  default_dir 
)

Definition at line 287 of file fileutils.cpp.

References jami::emitSignal(), and getFullPath().

Referenced by jami::Account::getProfileVcard(), and loadCacheTextFile().

Here is the call graph for this function:

◆ readArchive()

ArchiveStorageData jami::fileutils::readArchive ( const std::filesystem::path &  path,
std::string_view  scheme,
const std::string &  pwd 
)

◆ remove()

int jami::fileutils::remove ( const std::filesystem::path &  path,
bool  erase 
)

Definition at line 744 of file fileutils.cpp.

References jami::emitSignal(), and eraseFile().

Here is the call graph for this function:

◆ saveFile() [1/3]

void jami::fileutils::saveFile ( const std::filesystem::path &  path,
const std::vector< uint8_t > &  data,
mode_t  mode = 0644 
)
inline

Definition at line 106 of file fileutils.h.

References saveFile().

Here is the call graph for this function:

◆ saveFile() [2/3]

void jami::fileutils::saveFile ( const std::filesystem::path &  path,
const uint8_t data,
size_t  data_size,
mode_t  mode = 0644 
)

◆ saveFile() [3/3]

void jami::fileutils::saveFile ( const std::filesystem::path &  path,
const uint8_t data,
size_t  data_size,
mode_t UNUSED  mode 
)

Definition at line 314 of file fileutils.cpp.

References jami::emitSignal(), JAMI_ERROR, and JAMI_WARNING.

Referenced by saveFile(), and writeArchive().

Here is the call graph for this function:

◆ set_resource_dir_path()

LIBJAMI_PUBLIC void jami::fileutils::set_resource_dir_path ( const std::filesystem::path &  resourceDirPath)

Set the program's resource directory path.

This is used for clients that may be installed in different locations and are deployed with ringtones and other resources in an application relative directory.

Parameters
resource_dir_pathThe path to the ringtone directory.

Definition at line 126 of file fileutils.cpp.

References jami::emitSignal(), and resource_dir_path.

Referenced by libjami::setResourceDirPath().

Here is the call graph for this function:

◆ sha3File()

std::string jami::fileutils::sha3File ( const std::filesystem::path &  path)

Definition at line 759 of file fileutils.cpp.

References jami::emitSignal(), and JAMI_ERROR.

Referenced by jami::ConversationModule::onFileChannelRequest(), and jami::IncomingFile::process().

Here is the call graph for this function:

◆ sha3sum()

std::string jami::fileutils::sha3sum ( const std::vector< uint8_t > &  buffer)

Definition at line 794 of file fileutils.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ writeArchive()

bool jami::fileutils::writeArchive ( const std::string &  archive_str,
const std::filesystem::path &  path,
std::string_view  scheme,
const std::string &  password,
const std::vector< uint8_t > &  password_salt 
)

Variable Documentation

◆ ARCHIVE_AUTH_SCHEME_KEY

constexpr auto jami::fileutils::ARCHIVE_AUTH_SCHEME_KEY = "key"sv
staticconstexpr

Definition at line 116 of file fileutils.h.

Referenced by readArchive(), and writeArchive().

◆ ARCHIVE_AUTH_SCHEME_NONE

constexpr auto jami::fileutils::ARCHIVE_AUTH_SCHEME_NONE = ""sv
staticconstexpr

Definition at line 114 of file fileutils.h.

Referenced by writeArchive().

◆ ARCHIVE_AUTH_SCHEME_PASSWORD

constexpr auto jami::fileutils::ARCHIVE_AUTH_SCHEME_PASSWORD = "password"sv
staticconstexpr

Definition at line 115 of file fileutils.h.

Referenced by readArchive(), and writeArchive().

◆ resource_dir_path

std::filesystem::path jami::fileutils::resource_dir_path
static

Definition at line 123 of file fileutils.cpp.

Referenced by get_resource_dir_path(), and set_resource_dir_path().