s/isFileReadable/isReadableFile;

introduce isReadableDirectory
replace isReadable by either isReadableFile or isReadableDirectory
remove isReadable


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21769 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-11-25 11:18:16 +00:00
parent e7317582fb
commit d95451ae5c
21 changed files with 44 additions and 44 deletions

View File

@ -2504,7 +2504,7 @@ bool Buffer::readFileHelper(FileName const & s)
bool Buffer::loadLyXFile(FileName const & s) bool Buffer::loadLyXFile(FileName const & s)
{ {
if (s.isReadable()) { if (s.isReadableFile()) {
if (readFileHelper(s)) { if (readFileHelper(s)) {
lyxvc().file_found_hook(s); lyxvc().file_found_hook(s);
if (!s.isWritable()) if (!s.isWritable())

View File

@ -2025,7 +2025,7 @@ docstring BufferView::contentsOfPlaintextFile(string const & f,
fname = makeAbsPath(to_utf8(result.second)); fname = makeAbsPath(to_utf8(result.second));
} }
if (!fname.isReadable()) { if (!fname.isReadableFile()) {
docstring const error = from_ascii(strerror(errno)); docstring const error = from_ascii(strerror(errno));
docstring const file = makeDisplayPath(fname.absFilename(), 50); docstring const file = makeDisplayPath(fname.absFilename(), 50);
docstring const text = docstring const text =

View File

@ -320,7 +320,7 @@ bool Converters::convert(Buffer const * buffer,
"I use convertDefault.py:\n\t" << command); "I use convertDefault.py:\n\t" << command);
Systemcall one; Systemcall one;
one.startscript(Systemcall::Wait, command); one.startscript(Systemcall::Wait, command);
if (to_file.isFileReadable()) { if (to_file.isReadableFile()) {
if (conversionflags & try_cache) if (conversionflags & try_cache)
ConverterCache::get().add(orig_from, ConverterCache::get().add(orig_from,
to_format, to_file); to_format, to_file);

View File

@ -1945,7 +1945,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
filename = addName(lyxrc.document_path, filename = addName(lyxrc.document_path,
"newfile" + convert<string>(++newfile_number) + ".lyx"); "newfile" + convert<string>(++newfile_number) + ".lyx");
while (theBufferList().exists(filename) || while (theBufferList().exists(filename) ||
FileName(filename).isReadable()) { FileName(filename).isReadableFile()) {
++newfile_number; ++newfile_number;
filename = addName(lyxrc.document_path, filename = addName(lyxrc.document_path,
"newfile" + convert<string>(newfile_number) + "newfile" + convert<string>(newfile_number) +

View File

@ -57,13 +57,13 @@ bool LyXVC::file_found_hook(FileName const & fn)
{ {
FileName found_file; FileName found_file;
// Check if file is under RCS // Check if file is under RCS
if (!(found_file = RCS::find_file(fn)).empty()) { if (!(found_file = RCS::findFile(fn)).empty()) {
vcs.reset(new RCS(found_file)); vcs.reset(new RCS(found_file));
vcs->owner(owner_); vcs->owner(owner_);
return true; return true;
} }
// Check if file is under CVS // Check if file is under CVS
if (!(found_file = CVS::find_file(fn)).empty()) { if (!(found_file = CVS::findFile(fn)).empty()) {
vcs.reset(new CVS(found_file, fn)); vcs.reset(new CVS(found_file, fn));
vcs->owner(owner_); vcs->owner(owner_);
return true; return true;
@ -76,9 +76,9 @@ bool LyXVC::file_found_hook(FileName const & fn)
bool LyXVC::file_not_found_hook(FileName const & fn) bool LyXVC::file_not_found_hook(FileName const & fn)
{ {
// Check if file is under RCS // Check if file is under RCS
if (!RCS::find_file(fn).empty()) if (!RCS::findFile(fn).empty())
return true; return true;
if (!CVS::find_file(fn).empty()) if (!CVS::findFile(fn).empty())
return true; return true;
return false; return false;
} }
@ -95,7 +95,7 @@ void LyXVC::registrer()
FileName const filename = owner_->fileName(); FileName const filename = owner_->fileName();
// there must be a file to save // there must be a file to save
if (!filename.isFileReadable()) { if (!filename.isReadableFile()) {
Alert::error(_("Document not saved"), Alert::error(_("Document not saved"),
_("You must save the document " _("You must save the document "
"before it can be registered.")); "before it can be registered."));
@ -106,7 +106,7 @@ void LyXVC::registrer()
if (!vcs) { if (!vcs) {
FileName const cvs_entries(makeAbsPath("CVS/Entries")); FileName const cvs_entries(makeAbsPath("CVS/Entries"));
if (cvs_entries.isFileReadable()) { if (cvs_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering " LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with CVS"); << to_utf8(filename.displayName()) << " with CVS");
vcs.reset(new CVS(cvs_entries, filename)); vcs.reset(new CVS(cvs_entries, filename));

View File

@ -176,7 +176,7 @@ enum TextClassTags {
// Reads a textclass structure from file. // Reads a textclass structure from file.
bool TextClass::read(FileName const & filename, ReadType rt) bool TextClass::read(FileName const & filename, ReadType rt)
{ {
if (!filename.isFileReadable()) { if (!filename.isReadableFile()) {
lyxerr << "Cannot read layout file `" << filename << "'." lyxerr << "Cannot read layout file `" << filename << "'."
<< endl; << endl;
return true; return true;

View File

@ -75,12 +75,12 @@ RCS::RCS(FileName const & m)
} }
FileName const RCS::find_file(FileName const & file) FileName const RCS::findFile(FileName const & file)
{ {
// Check if *,v exists. // Check if *,v exists.
FileName tmp(file.absFilename() + ",v"); FileName tmp(file.absFilename() + ",v");
LYXERR(Debug::LYXVC, "Checking if file is under rcs: " << tmp); LYXERR(Debug::LYXVC, "Checking if file is under rcs: " << tmp);
if (tmp.isReadable()) { if (tmp.isReadableFile()) {
LYXERR(Debug::LYXVC, "Yes " << file << " is under rcs."); LYXERR(Debug::LYXVC, "Yes " << file << " is under rcs.");
return tmp; return tmp;
} }
@ -88,7 +88,7 @@ FileName const RCS::find_file(FileName const & file)
// Check if RCS/*,v exists. // Check if RCS/*,v exists.
tmp = FileName(addName(addPath(onlyPath(file.absFilename()), "RCS"), file.absFilename()) + ",v"); tmp = FileName(addName(addPath(onlyPath(file.absFilename()), "RCS"), file.absFilename()) + ",v");
LYXERR(Debug::LYXVC, "Checking if file is under rcs: " << tmp); LYXERR(Debug::LYXVC, "Checking if file is under rcs: " << tmp);
if (tmp.isReadable()) { if (tmp.isReadableFile()) {
LYXERR(Debug::LYXVC, "Yes " << file << " it is under rcs."); LYXERR(Debug::LYXVC, "Yes " << file << " it is under rcs.");
return tmp; return tmp;
} }
@ -232,7 +232,7 @@ CVS::CVS(FileName const & m, FileName const & f)
} }
FileName const CVS::find_file(FileName const & file) FileName const CVS::findFile(FileName const & file)
{ {
// First we look for the CVS/Entries in the same dir // First we look for the CVS/Entries in the same dir
// where we have file. // where we have file.
@ -240,7 +240,7 @@ FileName const CVS::find_file(FileName const & file)
string const tmpf = '/' + onlyFilename(file.absFilename()) + '/'; string const tmpf = '/' + onlyFilename(file.absFilename()) + '/';
LYXERR(Debug::LYXVC, "LyXVC: checking in `" << dir LYXERR(Debug::LYXVC, "LyXVC: checking in `" << dir
<< "' for `" << tmpf << '\''); << "' for `" << tmpf << '\'');
if (dir.isReadable()) { if (dir.isReadableDirectory()) {
// Ok we are at least in a CVS dir. Parse the CVS/Entries // Ok we are at least in a CVS dir. Parse the CVS/Entries
// and see if we can find this file. We do a fast and // and see if we can find this file. We do a fast and
// dirty parse here. // dirty parse here.

View File

@ -101,7 +101,7 @@ public:
RCS(support::FileName const & m); RCS(support::FileName const & m);
/// return the revision file for the given file, if found /// return the revision file for the given file, if found
static support::FileName const find_file(support::FileName const & file); static support::FileName const findFile(support::FileName const & file);
static void retrieve(support::FileName const & file); static void retrieve(support::FileName const & file);
@ -134,7 +134,7 @@ public:
CVS(support::FileName const & m, support::FileName const & f); CVS(support::FileName const & m, support::FileName const & f);
/// return the revision file for the given file, if found /// return the revision file for the given file, if found
static support::FileName const find_file(support::FileName const & file); static support::FileName const findFile(support::FileName const & file);
virtual void registrer(std::string const & msg); virtual void registrer(std::string const & msg);

View File

@ -90,7 +90,7 @@ Buffer * checkAndLoadLyXFile(FileName const & filename)
return 0; return 0;
} }
if (filename.isFileReadable()) { if (filename.isReadableFile()) {
Buffer * b = theBufferList().newBuffer(filename.absFilename()); Buffer * b = theBufferList().newBuffer(filename.absFilename());
if (!b->loadLyXFile(filename)) { if (!b->loadLyXFile(filename)) {
theBufferList().release(b); theBufferList().release(b);

View File

@ -807,7 +807,7 @@ string const GuiGraphics::readBB(string const & file)
bool GuiGraphics::isFilenameValid(string const & fname) const bool GuiGraphics::isFilenameValid(string const & fname) const
{ {
// It may be that the filename is relative. // It may be that the filename is relative.
return makeAbsPath(fname, bufferFilepath()).isFileReadable(); return makeAbsPath(fname, bufferFilepath()).isReadableFile();
} }

View File

@ -962,7 +962,7 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
} }
} }
else if (name == "latexlog") else if (name == "latexlog")
enable = FileName(buf->logName()).isFileReadable(); enable = FileName(buf->logName()).isReadableFile();
else if (name == "spellchecker") else if (name == "spellchecker")
#if defined (USE_ASPELL) || defined (USE_ISPELL) || defined (USE_PSPELL) #if defined (USE_ASPELL) || defined (USE_ISPELL) || defined (USE_PSPELL)
enable = !buf->isReadonly(); enable = !buf->isReadonly();

View File

@ -269,7 +269,7 @@ void CacheItem::Impl::imageConverted(bool success)
converter_.reset(); converter_.reset();
cc_.disconnect(); cc_.disconnect();
success = !file_to_load_.empty() && file_to_load_.isFileReadable(); success = !file_to_load_.empty() && file_to_load_.isReadableFile();
if (!success) { if (!success) {
LYXERR(Debug::GRAPHICS, "Unable to find converted file!"); LYXERR(Debug::GRAPHICS, "Unable to find converted file!");
@ -370,7 +370,7 @@ void CacheItem::Impl::convertToDisplayFormat()
setStatus(Converting); setStatus(Converting);
// First, check that the file exists! // First, check that the file exists!
if (!filename_.isFileReadable()) { if (!filename_.isReadableFile()) {
if (status_ != ErrorNoFile) { if (status_ != ErrorNoFile) {
setStatus(ErrorNoFile); setStatus(ErrorNoFile);
LYXERR(Debug::GRAPHICS, "\tThe file is not readable"); LYXERR(Debug::GRAPHICS, "\tThe file is not readable");

View File

@ -187,7 +187,7 @@ string const doSubstitution(InsetExternalParams const & params,
FileName const absfile( FileName const absfile(
support::makeAbsPath(file, masterBuffer->temppath())); support::makeAbsPath(file, masterBuffer->temppath()));
if (absfile.isFileReadable()) if (absfile.isReadableFile())
contents = absfile.fileContents(); contents = absfile.fileContents();
size_t const pos = result.find("$$Contents(\""); size_t const pos = result.find("$$Contents(\"");

View File

@ -140,7 +140,7 @@ string normalizeName(Buffer const & buffer, OutputParams const & runparams,
string const & name, string const & ext) string const & name, string const & ext)
{ {
string const fname = makeAbsPath(name, buffer.filePath()).absFilename(); string const fname = makeAbsPath(name, buffer.filePath()).absFilename();
if (absolutePath(name) || !FileName(fname + ext).isFileReadable()) if (absolutePath(name) || !FileName(fname + ext).isReadableFile())
return name; return name;
if (!runparams.nice) if (!runparams.nice)
return fname; return fname;
@ -195,7 +195,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
string database = string database =
normalizeName(buffer, runparams, utf8input, ".bib"); normalizeName(buffer, runparams, utf8input, ".bib");
FileName const try_in_file(makeAbsPath(database + ".bib", buffer.filePath())); FileName const try_in_file(makeAbsPath(database + ".bib", buffer.filePath()));
bool const not_from_texmf = try_in_file.isFileReadable(); bool const not_from_texmf = try_in_file.isReadableFile();
if (!runparams.inComment && !runparams.dryrun && !runparams.nice && if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
not_from_texmf) { not_from_texmf) {
@ -253,7 +253,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
if (!style.empty()) { if (!style.empty()) {
string base = normalizeName(buffer, runparams, style, ".bst"); string base = normalizeName(buffer, runparams, style, ".bst");
FileName const try_in_file(makeAbsPath(base + ".bst", buffer.filePath())); FileName const try_in_file(makeAbsPath(base + ".bst", buffer.filePath()));
bool const not_from_texmf = try_in_file.isFileReadable(); bool const not_from_texmf = try_in_file.isReadableFile();
// If this style does not come from texmf and we are not // If this style does not come from texmf and we are not
// exporting to .tex copy it to the tmp directory. // exporting to .tex copy it to the tmp directory.
// This prevents problems with spaces and 8bit charcaters // This prevents problems with spaces and 8bit charcaters

View File

@ -817,7 +817,7 @@ namespace {
bool preview_wanted(InsetExternalParams const & params) bool preview_wanted(InsetExternalParams const & params)
{ {
return params.display == external::PreviewDisplay && return params.display == external::PreviewDisplay &&
params.filename.isFileReadable(); params.filename.isReadableFile();
} }

View File

@ -611,7 +611,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
// not exist. // not exist.
// We are not going to change the extension or using the name of the // We are not going to change the extension or using the name of the
// temporary file, the code is already complicated enough. // temporary file, the code is already complicated enough.
if (runparams.inComment || !params().filename.isFileReadable()) if (runparams.inComment || !params().filename.isReadableFile())
return params().filename.outputFilename(masterBuffer->filePath()); return params().filename.outputFilename(masterBuffer->filePath());
// We place all temporary files in the master buffer's temp dir. // We place all temporary files in the master buffer's temp dir.
@ -783,7 +783,7 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os,
params().filename.relFilename(buf.filePath()); params().filename.relFilename(buf.filePath());
bool const file_exists = !params().filename.empty() bool const file_exists = !params().filename.empty()
&& params().filename.isFileReadable(); && params().filename.isReadableFile();
string const message = file_exists ? string const message = file_exists ?
string() : string("bb = 0 0 200 100, draft, type=eps"); string() : string("bb = 0 0 200 100, draft, type=eps");
// if !message.empty() then there was no existing file // if !message.empty() then there was no existing file

View File

@ -787,7 +787,7 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
FileName const included_file = includedFilename(buffer, params); FileName const included_file = includedFilename(buffer, params);
return type(params) == INPUT && params.preview() && return type(params) == INPUT && params.preview() &&
included_file.isFileReadable(); included_file.isReadableFile();
} }

View File

@ -217,10 +217,10 @@ bool FileName::isReadOnly() const
} }
bool FileName::isReadable() const bool FileName::isReadableDirectory() const
{ {
QFileInfo const fi(toqstr(name_)); QFileInfo const fi(toqstr(name_));
return fi.isReadable(); return fi.isDir() && fi.isReadable();
} }
@ -236,7 +236,7 @@ std::string FileName::onlyPath() const
} }
bool FileName::isFileReadable() const bool FileName::isReadableFile() const
{ {
QFileInfo const fi(toqstr(name_)); QFileInfo const fi(toqstr(name_));
return fi.isFile() && fi.isReadable(); return fi.isFile() && fi.isReadable();
@ -348,7 +348,7 @@ string FileName::guessFormatFromContents() const
// Z \037\235 UNIX compress // Z \037\235 UNIX compress
// paranoia check // paranoia check
if (empty() || !isFileReadable()) if (empty() || !isReadableFile())
return string(); return string();
ifstream ifs(toFilesystemEncoding().c_str()); ifstream ifs(toFilesystemEncoding().c_str());

View File

@ -64,9 +64,9 @@ public:
/// return true when it names a directory /// return true when it names a directory
bool isDirectory() const; bool isDirectory() const;
/// return true when file/directory is readable /// return true when file/directory is readable
bool isReadable() const; bool isReadableDirectory() const;
/// return true when it is a file and readable /// return true when it is a file and readable
bool isFileReadable() const; bool isReadableFile() const;
/// return true when file/directory is writable /// return true when file/directory is writable
bool isWritable() const; bool isWritable() const;
/// return true when file/directory is writable (write test file) /// return true when file/directory is writable (write test file)

View File

@ -231,7 +231,7 @@ FileName const fileSearch(string const & path, string const & name,
string const tmpname = replaceEnvironmentPath(name); string const tmpname = replaceEnvironmentPath(name);
FileName fullname(makeAbsPath(tmpname, path)); FileName fullname(makeAbsPath(tmpname, path));
// search first without extension, then with it. // search first without extension, then with it.
if (fullname.isFileReadable()) if (fullname.isReadableFile())
return fullname; return fullname;
if (ext.empty()) if (ext.empty())
// We are done. // We are done.
@ -240,7 +240,7 @@ FileName const fileSearch(string const & path, string const & name,
// fullname. // fullname.
if (getExtension(fullname.absFilename()) != ext) if (getExtension(fullname.absFilename()) != ext)
fullname = FileName(addExtension(fullname.absFilename(), ext)); fullname = FileName(addExtension(fullname.absFilename(), ext));
if (fullname.isFileReadable() || mode == allow_unreadable) if (fullname.isReadableFile() || mode == allow_unreadable)
return fullname; return fullname;
return FileName(); return FileName();
} }

View File

@ -92,7 +92,7 @@ string const trim(string const & a, char const * p)
void split(string const & s, vector<string> & result, char delim) void split(string const & s, vector<string> & result, char delim)
{ :{
//cerr << "split 1: '" << s << "'\n"; //cerr << "split 1: '" << s << "'\n";
istringstream is(s); istringstream is(s);
string t; string t;
@ -420,7 +420,7 @@ namespace {
* You must ensure that \p parentFilePath is properly set before calling * You must ensure that \p parentFilePath is properly set before calling
* this function! * this function!
*/ */
void tex2lyx(std::istream &is, std::ostream &os) void tex2lyx(std::istream & is, std::ostream & os)
{ {
Parser p(is); Parser p(is);
//p.dump(); //p.dump();
@ -451,7 +451,7 @@ void tex2lyx(std::istream &is, std::ostream &os)
/// convert TeX from \p infilename to LyX and write it to \p os /// convert TeX from \p infilename to LyX and write it to \p os
bool tex2lyx(FileName const & infilename, std::ostream &os) bool tex2lyx(FileName const & infilename, std::ostream & os)
{ {
ifstream is(infilename.toFilesystemEncoding().c_str()); ifstream is(infilename.toFilesystemEncoding().c_str());
if (!is.good()) { if (!is.good()) {
@ -469,9 +469,9 @@ bool tex2lyx(FileName const & infilename, std::ostream &os)
} // anonymous namespace } // anonymous namespace
bool tex2lyx(string const &infilename, FileName const &outfilename) bool tex2lyx(string const & infilename, FileName const & outfilename)
{ {
if (outfilename.isFileReadable()) { if (outfilename.isReadableFile()) {
if (overwrite_files) { if (overwrite_files) {
cerr << "Overwriting existing file " cerr << "Overwriting existing file "
<< outfilename << endl; << outfilename << endl;