20 #include <basic/options/keys/in.OptionKeys.gen.hh>
33 #if defined(MAC) || defined(__APPLE__) || defined(__OSX__) || defined(linux) || defined(__linux__) || defined(__linux)
57 std::string
const & db_file,
61 using namespace utility::excn;
63 if ( db_stream.
good() ) {
67 if ( db_file.length() == 0 ) {
75 TR <<
"Database file opened: " << db_file << std::endl;
78 std::stringstream err_msg;
80 <<
"Database file open failed for: \"" << db_file <<
"\"" << std::endl;
83 #ifdef __native_client__
84 throw(
"ERROR: Database file open failed for: " + db_file );
96 std::string
const & db_file,
101 using namespace basic::options::OptionKeys;
109 if ( warn )
Warning() <<
"Unable to locate database file " << db_file << std::endl;
117 std::string
const & cache_file,
123 TR.
Debug <<
"Using '" << cache_file <<
"' as the cached file." << std::endl;
135 std::ofstream tempfile( tempfilename.c_str() );
136 bool usable = tempfile.good();
140 TR.
Debug <<
"Using '" << cache_dir <<
"' as a cache directory." << std::endl;
152 std::string
const & short_name,
153 std::string
const & source_file,
158 using namespace basic::options::OptionKeys;
160 std::string cache_name;
163 if (
option[ in::path::database_cache_dir ].
user() ) {
164 cache_name = std::string(
option[ in::path::database_cache_dir ]()) + short_name;
170 char const *
path = getenv(
"ROSETTA3_DBCACHE");
172 cache_name = std::string(
path) +
"/" + short_name;
181 if ( source_file.size() != 0 ) {
189 char const * homedir = getenv(
"XDG_CONFIG_HOME");
190 if ( ! homedir || strlen(homedir) == 0 ) {
191 homedir = getenv(
"HOME");
193 #if defined(MAC) || defined(__APPLE__) || defined(__OSX__) || defined(linux) || defined(__linux__) || defined(__linux)
194 if ( ! homedir || strlen(homedir) == 0 ) {
195 passwd
const * unix_pwd( getpwuid(getuid()) );
197 homedir = unix_pwd->pw_dir;
202 if ( homedir && strlen(homedir) > 0 ) {
203 cache_name = std::string(homedir) +
"/.rosetta/database/" + short_name;
std::string full_name(std::string const &db_file, bool warn)
Full-path database file name.
static THREAD_LOCAL basic::Tracer TR("basic.io.database")
BooleanOptionKey const user("options:user")
Platform independent operations on files (except I/O)
FileName & path(std::string const &path_a)
Path assignment.
bool find_cache_file(std::string const &cache_file, bool dir_only)
Does cache file (absolute path) exist? if dir_only is true, will return true if the cache file could ...
std::string bare_name() const
Bare name (without volume or path or version)
File name class supporting Windows and UN*X/Linux format names.
Tracer & T(std::string const &channel, TracerPriority priority)
T is special function for assign tracer property on the static object.
common derived classes for thrown exceptions
std::string full_cache_name(std::string const &short_name, std::string const &source_file, bool for_writing)
Get the (absolute) path to a given cached file. If source_file is given, it's the full path to the so...
void close()
Close the ifstream and reset the state.
Functions for opening database files.
Tracer & Error(TracerPriority priority=t_error)
Predefined Error tracer.
bool open(utility::io::izstream &db_stream, std::string const &db_file, bool warn)
Open a database file on a provided stream.
izstream: Input file stream wrapper for uncompressed and compressed files
Input file stream wrapper for uncompressed and compressed files.
void clear()
Clear the stream(s)
bool create_directory_recursive(std::string const &dir_path)
Create a directory and its parent directories if they doesn't already exist.
rule< Scanner, options_closure::context_t > options
int file_delete(std::string const &path)
Delete File.
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
Path name class supporting Windows and UN*X/Linux format names.
vector1: std::vector with 1-based indexing
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
bool file_exists(std::string const &path)
Does File Exist?
rule< Scanner, string_closure::context_t > name
Program options global and initialization function.
std::string create_temp_filename(std::string const &dir, std::string const &prefix)
Find an unused random tempfile name with a given prefix (which may include a directory) ...
void open(std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::in)
Open a file.
rule< Scanner, option_closure::context_t > option