Am Sonntag, 18. Juni 2006 11:52 schrieb Uwe Stöhr:

> The command setting "photoshop $$i" gives me
> 
> Executing command: photoshop "04.jpg"
> 
> The path to the image is missing so that photoshop can't open the image.

The current working directory is changed to the image path before 
launching photoshop, so it should be able to find the image.

> The image path is relative to the document path. As the image is in the 
> same directory like the LyX-document, the image dialog don't pass its 
> path to "$$i".
> Is this a bug or is there a workaround?

It could be a race condition: The path is changed to the document dir, a 
child process is forked for starting photoshop, and the path is changed 
back again before photoshop is really started.

We should not use the Path class that does this magic, but rather use 
absolute paths. The attached patch does that for 1.5 and goes in right 
now, since Lars wrote several times that we should get rid of the Path 
class.


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

Reply via email to