0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-09 19:41:22 +01:00
construct/include/ircd/fs/fs.h

112 lines
3.6 KiB
C
Raw Normal View History

// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#define HAVE_IRCD_FS_H
/*
* Directory paths and filenames for UNIX systems.
* IRCD_PREFIX is set using ./configure --prefix, see INSTALL.
* Do not change these without corresponding changes in the build system.
*
* IRCD_PREFIX = prefix for all directories,
* DPATH = root directory of installation,
* BINPATH = directory for binary files,
* ETCPATH = directory for configuration files,
* LOGPATH = directory for logfiles,
* MODPATH = directory for modules,
* AUTOMODPATH = directory for autoloaded modules
*/
/// Tools for working with the local filesystem.
2017-10-12 02:43:11 +02:00
///
/// IRCd has wrapped operations for the local filesystem to maintain a
/// cross-platform implementation of asynchronous file IO in conjunction with
/// the ircd::ctx userspace context system. These operations will yield your
/// ircd::ctx when necessary to not block the event loop on the main thread
/// during IOs.
namespace ircd::fs
{
struct aio;
struct init;
IRCD_EXCEPTION(ircd::error, error)
IRCD_EXCEPTION(error, filesystem_error)
constexpr auto DPATH = IRCD_PREFIX;
constexpr auto BINPATH = IRCD_PREFIX "/bin";
constexpr auto ETCPATH = RB_ETC_DIR;
constexpr auto LOGPATH = RB_LOG_DIR;
2017-11-26 20:56:08 +01:00
constexpr auto MODPATH = RB_MODULE_DIR;
constexpr auto CPATH = RB_ETC_DIR "/ircd.conf"; // ircd.conf file
2017-11-26 20:56:08 +01:00
constexpr auto SPATH = RB_BIN_DIR "/" BRANDING_NAME; // ircd executable
constexpr auto DBPATH = PKGLOCALSTATEDIR "/db"; // database prefix
// Below are the elements for default paths.
enum index
{
PREFIX,
BIN,
ETC,
LOG,
LIBEXEC,
MODULES,
IRCD_CONF,
IRCD_EXEC,
DB,
2017-11-26 20:56:08 +01:00
_NUM_
};
const char *get(index) noexcept;
const char *name(index) noexcept;
2016-09-24 03:44:30 +02:00
std::string make_path(const std::initializer_list<std::string> &);
bool exists(const std::string &path);
bool is_dir(const std::string &path);
bool is_reg(const std::string &path);
2017-12-21 01:33:12 +01:00
size_t size(const std::string &path);
size_t size(const string_view &path);
std::vector<std::string> ls(const std::string &path);
std::vector<std::string> ls_recursive(const std::string &path);
std::string cwd();
void chdir(const std::string &path);
bool mkdir(const std::string &path);
2017-10-12 02:43:11 +02:00
// This suite of IO functions may yield your context.
bool write(const std::string &name, const const_raw_buffer &buf);
bool append(const std::string &name, const const_raw_buffer &buf);
bool overwrite(const std::string &name, const const_raw_buffer &buf);
bool overwrite(const string_view &name, const const_raw_buffer &buf);
extern aio *aioctx;
}
#include "read.h"
struct ircd::fs::init
{
init();
~init() noexcept;
};