]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
hopefully fix tex2lyx linking.
[lyx.git] / src / support / filetools.C
index ca5584211ef376414d70ad8440663f57f062a7af..c2d5453aef8b5463eee9c1dcf48a33fbf28d8c98 100644 (file)
@@ -133,11 +133,26 @@ string const makeLatexName(string const & file)
 }
 
 
-string const quoteName(string const & name)
+string const quoteName(string const & name, quote_style style)
 {
-       return (os::shell() == os::UNIX) ?
-               '\'' + name + '\'':
-               '"' + name + '"';
+       switch(style) {
+       case quote_shell:
+               // This does not work for filenames containing " (windows)
+               // or ' (all other OSes). This can't be changed easily, since
+               // we would need to adapt the command line parser in
+               // Forkedcall::generateChild. Therefore we don't pass user
+               // filenames to child processes if possible. We store them in
+               // a python script instead, where we don't have these
+               // limitations.
+               return (os::shell() == os::UNIX) ?
+                       '\'' + name + '\'':
+                       '"' + name + '"';
+       case quote_python:
+               return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
+                    + "\"";
+       }
+       // shut up stupid compiler
+       return string();
 }
 
 
@@ -313,7 +328,7 @@ string const i18nLibFileSearch(string const & dir, string const & name,
 }
 
 
-string const libScriptSearch(string const & command_in)
+string const libScriptSearch(string const & command_in, quote_style style)
 {
        static string const token_scriptpath = "$$s/";
 
@@ -339,7 +354,7 @@ string const libScriptSearch(string const & command_in)
        } else {
                // Replace "$$s/foo/some_script" with "<path to>/some_script".
                string::size_type const size_replace = size_script + 4;
-               command.replace(pos1, size_replace, quoteName(script));
+               command.replace(pos1, size_replace, quoteName(script, style));
        }
 
        return command;
@@ -375,7 +390,12 @@ string const createTmpDir(string const & tempdir, string const & mask)
 
 bool destroyDir(string const & tmpdir)
 {
-       return fs::remove_all(tmpdir) > 0;
+       try {
+               return fs::remove_all(tmpdir) > 0;
+       } catch (fs::filesystem_error const & fe){
+               lyxerr << "Could not delete " << tmpdir << ". (" << fe.what() << ")" << std::endl;
+               return false;
+       }
 }