Renamed path_open() -> path_streamopen()
This commit is contained in:
parent
4b928ee57e
commit
19eac2d7dc
@ -48,8 +48,12 @@ typedef int ssize_t;
|
|||||||
#define strcasecmp _stricmp
|
#define strcasecmp _stricmp
|
||||||
#define chdir _chdir
|
#define chdir _chdir
|
||||||
|
|
||||||
|
#ifndef R_OK
|
||||||
#define R_OK 4
|
#define R_OK 4
|
||||||
|
#endif
|
||||||
|
#ifndef W_OK
|
||||||
#define W_OK 2
|
#define W_OK 2
|
||||||
|
#endif
|
||||||
#ifndef X_OK
|
#ifndef X_OK
|
||||||
#define X_OK 4
|
#define X_OK 4
|
||||||
#endif
|
#endif
|
||||||
@ -59,6 +63,8 @@ typedef int ssize_t;
|
|||||||
|
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
#define PRETEND_USE(expr) ((void)(expr))
|
#ifndef PRETEND_USE
|
||||||
|
# define PRETEND_USE(expr) ((void)(expr))
|
||||||
|
#endif /* PRETEND_USE */
|
||||||
|
|
||||||
#endif /* INCLUDED */
|
#endif /* INCLUDED */
|
||||||
|
|||||||
@ -938,8 +938,8 @@ bool RclConfig::getMissingHelperDesc(string& out) const
|
|||||||
void RclConfig::storeMissingHelperDesc(const string &s)
|
void RclConfig::storeMissingHelperDesc(const string &s)
|
||||||
{
|
{
|
||||||
string fmiss = path_cat(getCacheDir(), "missing");
|
string fmiss = path_cat(getCacheDir(), "missing");
|
||||||
fstream fp = path_open(fmiss, ios::trunc | ios::out);
|
fstream fp;
|
||||||
if (fp.is_open()) {
|
if (path_streamopen(fmiss, ios::trunc | ios::out, fp)) {
|
||||||
fp << s;
|
fp << s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1787,8 +1787,8 @@ bool RclConfig::initUserConfig()
|
|||||||
for (int i = 0; i < ncffiles; i++) {
|
for (int i = 0; i < ncffiles; i++) {
|
||||||
string dst = path_cat(m_confdir, string(configfiles[i]));
|
string dst = path_cat(m_confdir, string(configfiles[i]));
|
||||||
if (!path_exists(dst)) {
|
if (!path_exists(dst)) {
|
||||||
fstream output = path_open(dst, ios::out);
|
fstream output;
|
||||||
if (output.is_open()) {
|
if (path_streamopen(dst, ios::out, output)) {
|
||||||
output << blurb << "\n";
|
output << blurb << "\n";
|
||||||
if (!strcmp(configfiles[i], "recoll.conf")) {
|
if (!strcmp(configfiles[i], "recoll.conf")) {
|
||||||
// Add improved unac_except_trans for some languages
|
// Add improved unac_except_trans for some languages
|
||||||
|
|||||||
@ -234,7 +234,7 @@ bool RclMain::maybeArgsToFile(vector<string>& args)
|
|||||||
string s;
|
string s;
|
||||||
stringsToString(args, s);
|
stringsToString(args, s);
|
||||||
fstream fout;
|
fstream fout;
|
||||||
if (!path_open(m_idxargstmp->filename(), ios::out|ios::trunc, fout)) {
|
if (!path_streamopen(m_idxargstmp->filename(), ios::out|ios::trunc, fout)) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
0, "Recoll", tr("Could not start recollindex (temp file error)"));
|
0, "Recoll", tr("Could not start recollindex (temp file error)"));
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -1158,8 +1158,8 @@ void RclMain::exportSimpleSearchHistory()
|
|||||||
}
|
}
|
||||||
string path = qs2utf8s(dialog.selectedFiles().value(0));
|
string path = qs2utf8s(dialog.selectedFiles().value(0));
|
||||||
LOGDEB("Chosen path: " << path << "\n");
|
LOGDEB("Chosen path: " << path << "\n");
|
||||||
std::fstream fp = path_open(path, std::ios::out | std::ios::trunc);
|
std::fstream fp;
|
||||||
if (!fp.is_open()) {
|
if (!path_streamopen(path, std::ios::out | std::ios::trunc, fp)) {
|
||||||
QMessageBox::warning(0, "Recoll", tr("Could not open/create file"));
|
QMessageBox::warning(0, "Recoll", tr("Could not open/create file"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -807,8 +807,8 @@ void ResTable::saveAsCSV()
|
|||||||
if (s.isEmpty())
|
if (s.isEmpty())
|
||||||
return;
|
return;
|
||||||
std::string tofile = qs2path(s);
|
std::string tofile = qs2path(s);
|
||||||
std::fstream fp = path_open(tofile, std::ios::out|std::ios::trunc);
|
std::fstream fp;
|
||||||
if (!fp.is_open()) {
|
if (!path_streamopen(tofile, std::ios::out|std::ios::trunc,fp)) {
|
||||||
QMessageBox::warning(0, "Recoll",
|
QMessageBox::warning(0, "Recoll",
|
||||||
tr("Can't open/create file: ") + s);
|
tr("Can't open/create file: ") + s);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -36,9 +36,9 @@ using namespace std;
|
|||||||
void WinSchedToolW::init()
|
void WinSchedToolW::init()
|
||||||
{
|
{
|
||||||
if (!theconfig) {
|
if (!theconfig) {
|
||||||
QMessageBox::warning(0, tr("Error"),
|
QMessageBox::warning(0, tr("Error"),
|
||||||
tr("Configuration not initialized"));
|
tr("Configuration not initialized"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(startPB, SIGNAL(clicked()), this, SLOT(startWinScheduler()));
|
connect(startPB, SIGNAL(clicked()), this, SLOT(startWinScheduler()));
|
||||||
@ -55,9 +55,15 @@ void WinSchedToolW::init()
|
|||||||
LOGDEB("WinSchedTool: batch file " << batchfile << endl);
|
LOGDEB("WinSchedTool: batch file " << batchfile << endl);
|
||||||
|
|
||||||
if (!path_exists(batchfile)) {
|
if (!path_exists(batchfile)) {
|
||||||
std::fstream fp = path_open(batchfile, ios::out|ios::trunc);
|
std::fstream fp;
|
||||||
fp << "\"" << recollindex << "\" -c \"" << confdir << "\"\n";
|
if (path_streamopen(batchfile, ios::out|ios::trunc, fp)) {
|
||||||
fp.close();
|
fp << "\"" << recollindex << "\" -c \"" << confdir << "\"\n";
|
||||||
|
fp.close();
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(0, tr("Error"),
|
||||||
|
tr("Could not create batch file"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QString blurb = tr(
|
QString blurb = tr(
|
||||||
"<h3>Recoll indexing batch scheduling</h3>"
|
"<h3>Recoll indexing batch scheduling</h3>"
|
||||||
|
|||||||
@ -284,8 +284,8 @@ void Db::Native::openWrite(const string& dir, Db::OpenMode mode)
|
|||||||
// Force Chert format, don't store the text.
|
// Force Chert format, don't store the text.
|
||||||
string stub = path_cat(m_rcldb->m_config->getConfDir(),
|
string stub = path_cat(m_rcldb->m_config->getConfDir(),
|
||||||
"xapian.stub");
|
"xapian.stub");
|
||||||
std::fstream fp = path_open(stub, std::ios::out|std::ios::trunc);
|
std::fstream fp;
|
||||||
if (!fp.is_open()) {
|
if (!path_streamopen(stub, std::ios::out|std::ios::trunc, fp)) {
|
||||||
throw(string("Can't create ") + stub);
|
throw(string("Can't create ") + stub);
|
||||||
}
|
}
|
||||||
fp << "chert " << dir << "\n";
|
fp << "chert " << dir << "\n";
|
||||||
|
|||||||
@ -235,7 +235,7 @@ ConfSimple::ConfSimple(const char *fname, int readonly, bool tildexp,
|
|||||||
mode |= ios::trunc;
|
mode |= ios::trunc;
|
||||||
}
|
}
|
||||||
fstream input;
|
fstream input;
|
||||||
path_open(fname, mode, input);
|
path_streamopen(fname, mode, input);
|
||||||
if (!input.is_open()) {
|
if (!input.is_open()) {
|
||||||
LOGDEB0("ConfSimple::ConfSimple: fstream(w)(" << fname << ", " << mode <<
|
LOGDEB0("ConfSimple::ConfSimple: fstream(w)(" << fname << ", " << mode <<
|
||||||
") errno " << errno << "\n");
|
") errno " << errno << "\n");
|
||||||
@ -246,7 +246,7 @@ ConfSimple::ConfSimple(const char *fname, int readonly, bool tildexp,
|
|||||||
input.clear();
|
input.clear();
|
||||||
status = STATUS_RO;
|
status = STATUS_RO;
|
||||||
// open readonly
|
// open readonly
|
||||||
path_open(fname, ios::in, input);
|
path_streamopen(fname, ios::in, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.is_open()) {
|
if (!input.is_open()) {
|
||||||
@ -579,7 +579,7 @@ bool ConfSimple::write()
|
|||||||
}
|
}
|
||||||
if (m_filename.length()) {
|
if (m_filename.length()) {
|
||||||
fstream output;
|
fstream output;
|
||||||
path_open(m_filename, ios::out | ios::trunc, output);
|
path_streamopen(m_filename, ios::out | ios::trunc, output);
|
||||||
if (!output.is_open()) {
|
if (!output.is_open()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -879,29 +879,7 @@ bool path_rmdir(const std::string& path)
|
|||||||
return RMDIR(syspath) == 0;
|
return RMDIR(syspath) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__GNUC__) || __GNUC__ > 4 || defined(__clang__)
|
bool path_streamopen(const std::string& path, int mode, std::fstream& outstream)
|
||||||
// Not sure what g++ version supports fstream assignment but 4.9
|
|
||||||
// (jessie) certainly does not
|
|
||||||
std::fstream path_open(const std::string& path, int mode)
|
|
||||||
{
|
|
||||||
#if defined(_WIN32) && defined (_MSC_VER)
|
|
||||||
// MSC STL has support for using wide chars in fstream
|
|
||||||
// constructor. We need this if, e.g. the user name/home directory
|
|
||||||
// is not ASCII. Actually don't know how to do this with gcc
|
|
||||||
wchar_t wpath[MAX_PATH + 1];
|
|
||||||
utf8towchar(path, wpath, MAX_PATH);
|
|
||||||
std::fstream ret(wpath, std::ios_base::openmode(mode));
|
|
||||||
if (!ret.is_open()) {
|
|
||||||
LOGERR("path_open("<< path << ", "<< mode <<") errno " << errno <<"\n");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
#else
|
|
||||||
return std::fstream(path, std::ios_base::openmode(mode));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool path_open(const std::string& path, int mode, std::fstream& outstream)
|
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && defined (_MSC_VER)
|
#if defined(_WIN32) && defined (_MSC_VER)
|
||||||
// MSC STL has support for using wide chars in fstream
|
// MSC STL has support for using wide chars in fstream
|
||||||
@ -910,15 +888,14 @@ bool path_open(const std::string& path, int mode, std::fstream& outstream)
|
|||||||
wchar_t wpath[MAX_PATH + 1];
|
wchar_t wpath[MAX_PATH + 1];
|
||||||
utf8towchar(path, wpath, MAX_PATH);
|
utf8towchar(path, wpath, MAX_PATH);
|
||||||
outstream.open(wpath, std::ios_base::openmode(mode));
|
outstream.open(wpath, std::ios_base::openmode(mode));
|
||||||
|
#else
|
||||||
|
outstream.open(path, std::ios_base::openmode(mode));
|
||||||
|
#endif
|
||||||
if (!outstream.is_open()) {
|
if (!outstream.is_open()) {
|
||||||
LOGERR("path_open("<< path << ", "<< mode <<") errno " << errno <<"\n");
|
LOGERR("path_streamopen("<<path<< ", "<<mode<<") errno "<<errno<<"\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
outstream.open(path, std::ios_base::openmode(mode));
|
|
||||||
return outstream.is_open();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool path_isdir(const string& path, bool follow)
|
bool path_isdir(const string& path, bool follow)
|
||||||
|
|||||||
@ -181,8 +181,7 @@ bool path_rmdir(const std::string& path);
|
|||||||
*
|
*
|
||||||
* @param path an utf-8 file path.
|
* @param path an utf-8 file path.
|
||||||
* @param mode is an std::fstream mode (ios::in etc.) */
|
* @param mode is an std::fstream mode (ios::in etc.) */
|
||||||
extern std::fstream path_open(const std::string& path, int mode);
|
extern bool path_streamopen(
|
||||||
extern bool path_open(
|
|
||||||
const std::string& path, int mode, std::fstream& outstream);
|
const std::string& path, int mode, std::fstream& outstream);
|
||||||
|
|
||||||
/// Encode according to rfc 1738
|
/// Encode according to rfc 1738
|
||||||
|
|||||||
@ -491,7 +491,7 @@ TempFile::Internal::Internal(const string& suffix)
|
|||||||
}
|
}
|
||||||
m_filename += suffix;
|
m_filename += suffix;
|
||||||
std::fstream fout;
|
std::fstream fout;
|
||||||
if (!path_open(m_filename, ios::out|ios::trunc, fout)) {
|
if (!path_streamopen(m_filename, ios::out|ios::trunc, fout)) {
|
||||||
m_reason = string("Open/create error. errno : ") +
|
m_reason = string("Open/create error. errno : ") +
|
||||||
lltodecstr(errno) + " file name: " + m_filename;
|
lltodecstr(errno) + " file name: " + m_filename;
|
||||||
LOGSYSERR("Tempfile::Internal::Internal", "open/create", m_filename);
|
LOGSYSERR("Tempfile::Internal::Internal", "open/create", m_filename);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user