Le 26 mai 07 à 22:11, Mael Hilléreau a écrit :

I found in the source (LyX 1.4.4) the function call (file converter.C, line 313):

bool Converters::convert(Buffer const * buffer,
                         string const & from_file, string const & to_file_base,
                         string const & from_format, string const & to_format,
                         string & to_file, bool try_default)
{
...
                        if (IsFileReadable(to_file)) {
                                return true;
...
}

Sorry, I made a mistake in previous message, the right function call is here (file GraphicsCacheItem.C, line 380):

...
        // First, check that the file exists!
        if (!IsFileReadable(filename_)) {
                if (status_ != ErrorNoFile) {
                        setStatus(ErrorNoFile);
                        lyxerr[Debug::GRAPHICS]
                                << "\tThe file is not readable" << endl;
                }
                return;
        }
...

Indeed, this function is defined as (fileTools.c, line 159):

// Is a file readable ?
bool IsFileReadable(string const & path)
{
return fs::exists(path) && !fs::is_directory(path) && fs::is_readable(path);
}

A short (and bad) fix would be to remove the "!fs::is_directory (path)" clause for the Mac OS version. But there's surely a way to check only for directories corresponding to packages. As I don't know Mac OS programming, does anybody have a clue?

According to Apple's "Bundle Programming Guide",

The Finder identifies packages by any of the following mechanisms:
* The directory has a known extension: .app, .bundle, .framework, .plugin, .kext, and so on.
* The directory has its bundle bit set.
* The directory has a known structure type indicating it is a modern or versioned bundle.

As a conclusion, as it is really not easy to distinguish between folders, applications, ..., and packages corresponding to graphics (such as '.graffle' files), I would suggest to replace the function call by a different one, and to consider folders having an extension to be valid files (only for Mac OS of course...). In the case the chosen package isn't supported (i.e. it is a folder or anything else but supported graphics), LyX won't crash because the file format won't be recognized.

I think (not tested) that replacing the line 381 (in GraphicsCacheItem.C) with the following should do the job:

if (!(fs::exists(filename_) && (!fs::is_directory(filename_) || fs::extension(filename_) != "") && fs::is_readable(filename_))) {

... assuming that 'fs' is known (namespace fs = boost::filesystem;)

Please, tell me what you think of this.

Mael.

--
Mael Hilléreau
http://mael.hillereau.free.fr



Reply via email to