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;
122 using namespace utility::io;
126 izstream potential_file( filename );
127 if ( potential_file.
good() ) {
130 izstream potential_file( path + filename);
131 if ( potential_file.
good() ) {
135 " nor " +
"./" + filename +
136 " nor " + path + filename +
" exists." );
139 return "WHAT THE @#$%!";
152 using namespace utility::io;
156 izstream potential_file( filename );
157 if ( potential_file.
good() ) {
160 izstream potential_file( filename + ext );
161 if ( potential_file.
good() ) {
162 return filename + ext;
164 izstream potential_file( path + filename);
165 if ( potential_file.
good() ) {
168 izstream potential_file( path + filename + ext );
169 if ( potential_file.
good() ) {
170 return path + filename + ext;
173 " nor " +
"./" + filename + ext +
174 " nor " + path + filename +
175 " nor " + path + filename + ext +
" exists." );
180 return "WHAT THE @#$%!";
188 std::string
const & cache_file,
194 TR.
Debug <<
"Using '" << cache_file <<
"' as the cached file." << std::endl;
206 std::ofstream tempfile( tempfilename.c_str() );
207 bool usable = tempfile.good();
211 TR.
Debug <<
"Using '" << cache_dir <<
"' as a cache directory." << std::endl;
223 std::string
const & short_name,
224 std::string
const & source_file,
229 using namespace basic::options::OptionKeys;
231 std::string cache_name;
241 char const *
path = getenv(
"ROSETTA3_DBCACHE");
243 cache_name = std::string(
path) +
"/" + short_name;
252 if ( source_file.size() != 0 ) {
260 char const * homedir = getenv(
"XDG_CONFIG_HOME");
261 if ( ! homedir || strlen(homedir) == 0 ) {
262 homedir = getenv(
"HOME");
264 #if defined(MAC) || defined(__APPLE__) || defined(__OSX__) || defined(linux) || defined(__linux__) || defined(__linux)
265 if ( ! homedir || strlen(homedir) == 0 ) {
266 passwd
const * unix_pwd( getpwuid(getuid()) );
268 homedir = unix_pwd->pw_dir;
273 if ( homedir && strlen(homedir) > 0 ) {
274 cache_name = std::string(homedir) +
"/.rosetta/database/" + short_name;
#define utility_exit_with_message(m)
Exit with file + line + message.
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")
std::string find_database_path(std::string dir, std::string filename)
Find a path to a file.
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)
basic::options::OptionKeys collection
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
PathVectorOptionKey const path
PathOptionKey const database_cache_dir("in:path:database_cache_dir")
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
PathVectorOptionKey const database("in:path:database")
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.
StringOptionKey const user
rule< Scanner, option_closure::context_t > option