* src/format.C

(Formats::view): Call the viewer with the absolute filename instead
	of changing the working directory to avoid a race condition on
	systems with a slow fork().
	(Formats::edit): Ditto (editor instead of viewer)


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14142 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-06-18 10:51:59 +00:00
parent 40d8a3cce5
commit 3ac0c3f587

View File

@ -23,19 +23,17 @@
#include "support/filetools.h" #include "support/filetools.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/os.h" #include "support/os.h"
#include "support/path.h"
#include "support/systemcall.h" #include "support/systemcall.h"
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
using lyx::support::absolutePath;
using lyx::support::bformat; using lyx::support::bformat;
using lyx::support::compare_ascii_no_case; using lyx::support::compare_ascii_no_case;
using lyx::support::contains; using lyx::support::contains;
using lyx::support::libScriptSearch; using lyx::support::libScriptSearch;
using lyx::support::makeDisplayPath; using lyx::support::makeDisplayPath;
using lyx::support::onlyFilename;
using lyx::support::onlyPath; using lyx::support::onlyPath;
using lyx::support::Path;
using lyx::support::quoteName; using lyx::support::quoteName;
using lyx::support::subst; using lyx::support::subst;
using lyx::support::Systemcall; using lyx::support::Systemcall;
@ -262,6 +260,7 @@ void Formats::setViewer(string const & name, string const & command)
bool Formats::view(Buffer const & buffer, string const & filename, bool Formats::view(Buffer const & buffer, string const & filename,
string const & format_name) const string const & format_name) const
{ {
BOOST_ASSERT(absolutePath(filename));
if (filename.empty() || !fs::exists(filename)) { if (filename.empty() || !fs::exists(filename)) {
Alert::error(_("Cannot view file"), Alert::error(_("Cannot view file"),
bformat(_("File does not exist: %1$s"), bformat(_("File does not exist: %1$s"),
@ -309,14 +308,12 @@ bool Formats::view(Buffer const & buffer, string const & filename,
if (!contains(command, token_from)) if (!contains(command, token_from))
command += ' ' + token_from; command += ' ' + token_from;
command = subst(command, token_from, command = subst(command, token_from, quoteName(filename));
quoteName(onlyFilename(filename)));
command = subst(command, token_path, quoteName(onlyPath(filename))); command = subst(command, token_path, quoteName(onlyPath(filename)));
command = subst(command, token_socket, quoteName(lyxsocket->address())); command = subst(command, token_socket, quoteName(lyxsocket->address()));
lyxerr[Debug::FILES] << "Executing command: " << command << std::endl; lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
buffer.message(_("Executing command: ") + command); buffer.message(_("Executing command: ") + command);
Path p(onlyPath(filename));
Systemcall one; Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command); int const res = one.startscript(Systemcall::DontWait, command);
@ -333,6 +330,7 @@ bool Formats::view(Buffer const & buffer, string const & filename,
bool Formats::edit(Buffer const & buffer, string const & filename, bool Formats::edit(Buffer const & buffer, string const & filename,
string const & format_name) const string const & format_name) const
{ {
BOOST_ASSERT(absolutePath(filename));
if (filename.empty() || !fs::exists(filename)) { if (filename.empty() || !fs::exists(filename)) {
Alert::error(_("Cannot edit file"), Alert::error(_("Cannot edit file"),
bformat(_("File does not exist: %1$s"), bformat(_("File does not exist: %1$s"),
@ -369,14 +367,12 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
if (!contains(command, token_from)) if (!contains(command, token_from))
command += ' ' + token_from; command += ' ' + token_from;
command = subst(command, token_from, command = subst(command, token_from, quoteName(filename));
quoteName(onlyFilename(filename)));
command = subst(command, token_path, quoteName(onlyPath(filename))); command = subst(command, token_path, quoteName(onlyPath(filename)));
command = subst(command, token_socket, quoteName(lyxsocket->address())); command = subst(command, token_socket, quoteName(lyxsocket->address()));
lyxerr[Debug::FILES] << "Executing command: " << command << std::endl; lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
buffer.message(_("Executing command: ") + command); buffer.message(_("Executing command: ") + command);
Path p(onlyPath(filename));
Systemcall one; Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command); int const res = one.startscript(Systemcall::DontWait, command);