3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
8 * \author Ivan Schreter
9 * \author Dirk Niggemann
10 * \author Asger Alstrup
11 * \author Lars Gullik Bjønnes
12 * \author Jean-Marc Lasgouttes
13 * \author Angus Leeming
17 * Full author contact details are available in file CREDITS.
19 * General path-mangling functions
24 #include "support/filetools.h"
26 #include "support/debug.h"
27 #include "support/environment.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
30 #include "support/os.h"
31 #include "support/Package.h"
32 #include "support/Path.h"
33 #include "support/Systemcall.h"
34 #include "support/qstring_helpers.h"
38 #include "support/lassert.h"
39 #include "support/regex.h"
63 bool isLyXFileName(string const & filename)
65 return suffixIs(ascii_lowercase(filename), ".lyx");
69 bool isSGMLFileName(string const & filename)
71 return suffixIs(ascii_lowercase(filename), ".sgml");
75 bool isValidLaTeXFileName(string const & filename)
77 string const invalid_chars("#%\"");
78 return filename.find_first_of(invalid_chars) == string::npos;
82 bool isValidDVIFileName(string const & filename)
84 string const invalid_chars("${}()[]^");
85 return filename.find_first_of(invalid_chars) == string::npos;
89 string const latex_path(string const & original_path,
90 latex_path_extension extension,
93 // On cygwin, we may need windows or posix style paths.
94 string path = os::latex_path(original_path);
95 path = subst(path, "~", "\\string~");
96 if (path.find(' ') != string::npos) {
97 // We can't use '"' because " is sometimes active (e.g. if
98 // babel is loaded with the "german" option)
99 if (extension == EXCLUDE_EXTENSION) {
100 // ChangeExtension calls os::internal_path internally
101 // so don't use it to remove the extension.
102 string const ext = getExtension(path);
103 string const base = ext.empty() ?
105 path.substr(0, path.length() - ext.length() - 1);
106 // ChangeExtension calls os::internal_path internally
107 // so don't use it to re-add the extension.
108 path = "\\string\"" + base + "\\string\"." + ext;
110 path = "\\string\"" + path + "\\string\"";
114 return dots == ESCAPE_DOTS ? subst(path, ".", "\\lyxdot ") : path;
118 // Substitutes spaces with underscores in filename (and path)
119 FileName const makeLatexName(FileName const & file)
121 string name = file.onlyFileName();
122 string const path = file.onlyPath().absFileName() + "/";
124 // ok so we scan through the string twice, but who cares.
125 // FIXME: in Unicode time this will break for sure! There is
126 // a non-latin world out there...
127 string const keep = "abcdefghijklmnopqrstuvwxyz"
128 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
129 "@!'()*+,-./0123456789:;<=>?[]`|";
131 string::size_type pos = 0;
132 while ((pos = name.find_first_not_of(keep, pos)) != string::npos)
135 FileName latex_name(path + name);
136 latex_name.changeExtension(".tex");
141 string const quoteName(string const & name, quote_style style)
145 // This does not work on native Windows for filenames
146 // containing the following characters < > : " / \ | ? *
147 // Moreover, it can't be made to work, as, according to
148 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
149 // those are reserved characters, and thus are forbidden.
150 // Please, also note that the command-line parser in
151 // ForkedCall::generateChild cannot deal with filenames
152 // containing " or ', therefore we don't pass user filenames
153 // to child processes if possible. We store them in a python
154 // script instead, where we don't have these limitations.
156 return (os::shell() == os::UNIX) ?
157 '\'' + subst(name, "'", "\'\\\'\'") + '\'' :
160 // According to the QProcess parser, a single double
161 // quote is represented by three consecutive ones.
162 // Here we simply escape the double quote and let our
163 // simple parser in Systemcall.cpp do the substitution.
164 return '"' + subst(name, "\"", "\\\"") + '"';
167 return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
170 // shut up stupid compiler
176 // Uses a string of paths separated by ";"s to find a file to open.
177 // Can't cope with pathnames with a ';' in them. Returns full path to file.
178 // If path entry begins with $$LyX/, use system_lyxdir
179 // If path entry begins with $$User/, use user_lyxdir
180 // Example: "$$User/doc;$$LyX/doc"
181 FileName const fileOpenSearch(string const & path, string const & name,
186 bool notfound = true;
187 string tmppath = split(path, path_element, ';');
189 while (notfound && !path_element.empty()) {
190 path_element = os::internal_path(path_element);
191 if (!suffixIs(path_element, '/'))
193 path_element = subst(path_element, "$$LyX",
194 package().system_support().absFileName());
195 path_element = subst(path_element, "$$User",
196 package().user_support().absFileName());
198 real_file = fileSearch(path_element, name, ext);
200 if (real_file.empty()) {
202 tmppath = split(tmppath, path_element, ';');
203 } while (!tmppath.empty() && path_element.empty());
213 // Returns the real name of file name in directory path, with optional
215 FileName const fileSearch(string const & path, string const & name,
216 string const & ext, search_mode mode)
218 // if `name' is an absolute path, we ignore the setting of `path'
219 // Expand Environmentvariables in 'name'
220 string const tmpname = replaceEnvironmentPath(name);
221 FileName fullname(makeAbsPath(tmpname, path));
222 // search first without extension, then with it.
223 if (fullname.isReadableFile())
227 return mode == may_not_exist ? fullname : FileName();
228 // Only add the extension if it is not already the extension of
230 if (getExtension(fullname.absFileName()) != ext)
231 fullname = FileName(addExtension(fullname.absFileName(), ext));
232 if (fullname.isReadableFile() || mode == may_not_exist)
238 // Search the file name.ext in the subdirectory dir of
240 // 2) build_lyxdir (if not empty)
242 FileName const libFileSearch(string const & dir, string const & name,
245 FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
247 if (!fullname.empty())
250 if (!package().build_support().empty())
251 fullname = fileSearch(addPath(package().build_support().absFileName(), dir),
253 if (!fullname.empty())
256 return fileSearch(addPath(package().system_support().absFileName(), dir), name, ext);
260 FileName const i18nLibFileSearch(string const & dir, string const & name,
263 /* The highest priority value is the `LANGUAGE' environment
264 variable. But we don't use the value if the currently
265 selected locale is the C locale. This is a GNU extension.
267 Otherwise, w use a trick to guess what support/gettext.has done:
268 each po file is able to tell us its name. (JMarc)
271 string lang = to_ascii(_(languageTestString()));
272 string const language = getEnv("LANGUAGE");
273 if (!lang.empty() && !language.empty())
277 lang = split(lang, l, ':');
280 // First try with the full name
281 tmp = libFileSearch(addPath(dir, l), name, ext);
285 // Then the name without country code
286 string const shortl = token(l, '_', 0);
288 tmp = libFileSearch(addPath(dir, shortl), name, ext);
294 // For compatibility, to be removed later (JMarc)
295 tmp = libFileSearch(dir, token(l, '_', 0) + '_' + name,
298 lyxerr << "i18nLibFileSearch: File `" << tmp
299 << "' has been found by the old method" <<endl;
303 lang = split(lang, l, ':');
306 return libFileSearch(dir, name, ext);
310 string const libScriptSearch(string const & command_in, quote_style style)
312 static string const token_scriptpath = "$$s/";
314 string command = command_in;
315 // Find the starting position of "$$s/"
316 string::size_type const pos1 = command.find(token_scriptpath);
317 if (pos1 == string::npos)
319 // Find the end of the "$$s/some_subdir/some_script" word within
320 // command. Assumes that the script name does not contain spaces.
321 string::size_type const start_script = pos1 + 4;
322 string::size_type const pos2 = command.find(' ', start_script);
323 string::size_type const size_script = pos2 == string::npos?
324 (command.size() - start_script) : pos2 - start_script;
326 // Does this script file exist?
327 string const script =
328 libFileSearch(".", command.substr(start_script, size_script)).absFileName();
330 if (script.empty()) {
331 // Replace "$$s/" with ""
332 command.erase(pos1, 4);
334 // Replace "$$s/foo/some_script" with "<path to>/some_script".
335 string::size_type const size_replace = size_script + 4;
336 command.replace(pos1, size_replace, quoteName(script, style));
343 static FileName createTmpDir(FileName const & tempdir, string const & mask)
345 LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
346 << "createTmpDir: mask=`" << mask << '\'');
348 FileName const tmpfl = FileName::tempName(tempdir, mask);
350 if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
351 LYXERR0("LyX could not create temporary directory in " << tempdir
360 FileName const createLyXTmpDir(FileName const & deflt)
362 if (deflt.empty() || deflt == package().system_temp_dir())
363 return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
365 if (deflt.createDirectory(0777))
368 if (deflt.isDirWritable()) {
369 // deflt could not be created because it
370 // did exist already, so let's create our own
372 return createTmpDir(deflt, "lyx_tmpdir");
374 // some other error occured.
375 return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
380 // Strip filename from path name
381 string const onlyPath(string const & filename)
383 // If empty filename, return empty
384 if (filename.empty())
387 // Find last / or start of filename
388 size_t j = filename.rfind('/');
389 return j == string::npos ? "./" : filename.substr(0, j + 1);
393 // Convert relative path into absolute path based on a basepath.
394 // If relpath is absolute, just use that.
395 // If basepath is empty, use CWD as base.
396 // Note that basePath can be a relative path, in the sense that it may
397 // not begin with "/" (e.g.), but it should NOT contain such constructs
399 // FIXME It might be nice if the code didn't simply assume that.
400 FileName const makeAbsPath(string const & relPath, string const & basePath)
402 // checks for already absolute path
403 if (FileName::isAbsolute(relPath))
404 return FileName(relPath);
406 // Copies given paths
407 string tempRel = os::internal_path(relPath);
408 // Since TempRel is NOT absolute, we can safely replace "//" with "/"
409 tempRel = subst(tempRel, "//", "/");
413 if (FileName::isAbsolute(basePath))
416 tempBase = addPath(FileName::getcwd().absFileName(), basePath);
418 // Handle /./ at the end of the path
419 while (suffixIs(tempBase, "/./"))
420 tempBase.erase(tempBase.length() - 2);
422 // processes relative path
423 string rTemp = tempRel;
426 // Check for a leading "~"
428 rTemp = split(rTemp, temp, '/');
430 tempBase = package().home_dir().absFileName();
435 while (!rTemp.empty()) {
437 rTemp = split(rTemp, temp, '/');
439 if (temp == ".") continue;
441 // Remove one level of TempBase
442 if (tempBase.length() <= 1) {
443 //this is supposed to be an absolute path, so...
447 //erase a trailing slash if there is one
448 if (suffixIs(tempBase, "/"))
449 tempBase.erase(tempBase.length() - 1, string::npos);
451 string::size_type i = tempBase.length() - 1;
452 while (i > 0 && tempBase[i] != '/')
455 tempBase.erase(i, string::npos);
458 } else if (temp.empty() && !rTemp.empty()) {
459 tempBase = os::current_root() + rTemp;
462 // Add this piece to TempBase
463 if (!suffixIs(tempBase, '/'))
469 // returns absolute path
470 return FileName(tempBase);
474 // Correctly append filename to the pathname.
475 // If pathname is '.', then don't use pathname.
476 // Chops any path of filename.
477 string const addName(string const & path, string const & fname)
479 string const basename = onlyFileName(fname);
482 if (path != "." && path != "./" && !path.empty()) {
483 buf = os::internal_path(path);
484 if (!suffixIs(path, '/'))
488 return buf + basename;
492 // Strips path from filename
493 string const onlyFileName(string const & fname)
498 string::size_type j = fname.rfind('/');
499 if (j == string::npos) // no '/' in fname
503 return fname.substr(j + 1);
507 // Create absolute path. If impossible, don't do anything
508 // Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
509 string const expandPath(string const & path)
511 // checks for already absolute path
512 string rTemp = replaceEnvironmentPath(path);
513 if (FileName::isAbsolute(rTemp))
517 string const copy = rTemp;
520 rTemp = split(rTemp, temp, '/');
523 return FileName::getcwd().absFileName() + '/' + rTemp;
526 return package().home_dir().absFileName() + '/' + rTemp;
529 return makeAbsPath(copy).absFileName();
531 // Don't know how to handle this
536 // Search the string for ${VAR} and $VAR and replace VAR using getenv.
537 string const replaceEnvironmentPath(string const & path)
539 // ${VAR} is defined as
540 // $\{[A-Za-z_][A-Za-z_0-9]*\}
541 static string const envvar_br = "[$]\\{([A-Za-z_][A-Za-z_0-9]*)\\}";
543 // $VAR is defined as:
544 // $[A-Za-z_][A-Za-z_0-9]*
545 static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
547 static regex envvar_br_re("(.*)" + envvar_br + "(.*)");
548 static regex envvar_re("(.*)" + envvar + "(.*)");
549 string result = path;
552 regex_match(result, what, envvar_br_re);
553 if (!what[0].matched) {
554 regex_match(result, what, envvar_re);
555 if (!what[0].matched) {
559 string env_var = getEnv(what.str(2));
560 result = what.str(1) + env_var + what.str(3);
566 // Make relative path out of two absolute paths
567 docstring const makeRelPath(docstring const & abspath, docstring const & basepath)
568 // Makes relative path out of absolute path. If it is deeper than basepath,
569 // it's easy. If basepath and abspath share something (they are all deeper
570 // than some directory), it'll be rendered using ..'s. If they are completely
571 // different, then the absolute path will be used as relative path.
573 docstring::size_type const abslen = abspath.length();
574 docstring::size_type const baselen = basepath.length();
576 docstring::size_type i = os::common_path(abspath, basepath);
579 // actually no match - cannot make it relative
583 // Count how many dirs there are in basepath above match
584 // and append as many '..''s into relpath
586 docstring::size_type j = i;
587 while (j < baselen) {
588 if (basepath[j] == '/') {
589 if (j + 1 == baselen)
596 // Append relative stuff from common directory to abspath
597 if (abspath[i] == '/')
599 for (; i < abslen; ++i)
602 if (suffixIs(buf, '/'))
603 buf.erase(buf.length() - 1);
604 // Substitute empty with .
611 // Append sub-directory(ies) to a path in an intelligent way
612 string const addPath(string const & path, string const & path_2)
615 string const path2 = os::internal_path(path_2);
617 if (!path.empty() && path != "." && path != "./") {
618 buf = os::internal_path(path);
619 if (path[path.length() - 1] != '/')
623 if (!path2.empty()) {
624 string::size_type const p2start = path2.find_first_not_of('/');
625 string::size_type const p2end = path2.find_last_not_of('/');
626 string const tmp = path2.substr(p2start, p2end - p2start + 1);
633 string const changeExtension(string const & oldname, string const & extension)
635 string::size_type const last_slash = oldname.rfind('/');
636 string::size_type last_dot = oldname.rfind('.');
637 if (last_dot < last_slash && last_slash != string::npos)
638 last_dot = string::npos;
641 // Make sure the extension starts with a dot
642 if (!extension.empty() && extension[0] != '.')
643 ext= '.' + extension;
647 return os::internal_path(oldname.substr(0, last_dot) + ext);
651 string const removeExtension(string const & name)
653 return changeExtension(name, string());
657 string const addExtension(string const & name, string const & extension)
659 if (!extension.empty() && extension[0] != '.')
660 return name + '.' + extension;
661 return name + extension;
665 /// Return the extension of the file (not including the .)
666 string const getExtension(string const & name)
668 string::size_type const last_slash = name.rfind('/');
669 string::size_type const last_dot = name.rfind('.');
670 if (last_dot != string::npos &&
671 (last_slash == string::npos || last_dot > last_slash))
672 return name.substr(last_dot + 1,
673 name.length() - (last_dot + 1));
679 string const unzippedFileName(string const & zipped_file)
681 string const ext = getExtension(zipped_file);
682 if (ext == "gz" || ext == "z" || ext == "Z")
683 return changeExtension(zipped_file, string());
684 return onlyPath(zipped_file) + "unzipped_" + onlyFileName(zipped_file);
688 FileName const unzipFile(FileName const & zipped_file, string const & unzipped_file)
690 FileName const tempfile = FileName(unzipped_file.empty() ?
691 unzippedFileName(zipped_file.toFilesystemEncoding()) :
694 string const command = "gunzip -c " +
695 zipped_file.toFilesystemEncoding() + " > " +
696 tempfile.toFilesystemEncoding();
698 one.startscript(Systemcall::Wait, command);
699 // test that command was executed successfully (anon)
700 // yes, please do. (Lgb)
705 docstring const makeDisplayPath(string const & path, unsigned int threshold)
709 // If file is from LyXDir, display it as if it were relative.
710 string const system = package().system_support().absFileName();
711 if (prefixIs(str, system) && str != system)
712 return from_utf8("[" + str.erase(0, system.length()) + "]");
714 // replace /home/blah with ~/
715 string const home = package().home_dir().absFileName();
716 if (!home.empty() && prefixIs(str, home))
717 str = subst(str, home, "~");
719 if (str.length() <= threshold)
720 return from_utf8(os::external_path(str));
722 string const prefix = ".../";
725 while (str.length() > threshold)
726 str = split(str, temp, '/');
728 // Did we shorten everything away?
730 // Yes, filename itself is too long.
731 // Pick the start and the end of the filename.
732 str = onlyFileName(path);
733 string const head = str.substr(0, threshold / 2 - 3);
735 string::size_type len = str.length();
737 str.substr(len - threshold / 2 - 2, len - 1);
738 str = head + "..." + tail;
741 return from_utf8(os::external_path(prefix + str));
746 bool readLink(FileName const & file, FileName & link)
748 char linkbuffer[PATH_MAX + 1];
749 string const encoded = file.toFilesystemEncoding();
750 int const nRead = ::readlink(encoded.c_str(),
751 linkbuffer, sizeof(linkbuffer) - 1);
754 linkbuffer[nRead] = '\0'; // terminator
755 link = makeAbsPath(linkbuffer, onlyPath(file.absFileName()));
759 bool readLink(FileName const &, FileName &)
766 cmd_ret const runCommand(string const & cmd)
768 // FIXME: replace all calls to RunCommand with ForkedCall
769 // (if the output is not needed) or the code in ISpell.cpp
770 // (if the output is needed).
772 // One question is if we should use popen or
773 // create our own popen based on fork, exec, pipe
774 // of course the best would be to have a
775 // pstream (process stream), with the
776 // variants ipstream, opstream
781 PROCESS_INFORMATION process;
782 SECURITY_ATTRIBUTES security;
786 security.nLength = sizeof(SECURITY_ATTRIBUTES);
787 security.bInheritHandle = TRUE;
788 security.lpSecurityDescriptor = NULL;
790 if (CreatePipe(&in, &out, &security, 0)) {
791 memset(&startup, 0, sizeof(STARTUPINFO));
792 memset(&process, 0, sizeof(PROCESS_INFORMATION));
794 startup.cb = sizeof(STARTUPINFO);
795 startup.dwFlags = STARTF_USESTDHANDLES;
797 startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
798 startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
799 startup.hStdOutput = out;
801 if (CreateProcess(0, (LPTSTR)cmd.c_str(), &security, &security,
802 TRUE, CREATE_NO_WINDOW, 0, 0, &startup, &process)) {
804 CloseHandle(process.hThread);
805 fno = _open_osfhandle((long)in, _O_RDONLY);
807 inf = _fdopen(fno, "r");
810 #elif defined (HAVE_POPEN)
811 FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode());
812 #elif defined (HAVE__POPEN)
813 FILE * inf = ::_popen(cmd.c_str(), os::popen_read_mode());
815 #error No popen() function.
818 // (Claus Hentschel) Check if popen was successful ;-)
820 lyxerr << "RunCommand:: could not start child process" << endl;
821 return make_pair(-1, string());
827 ret += static_cast<char>(c);
832 WaitForSingleObject(process.hProcess, INFINITE);
833 CloseHandle(process.hProcess);
834 int const pret = fclose(inf);
835 #elif defined (HAVE_PCLOSE)
836 int const pret = pclose(inf);
837 #elif defined (HAVE__PCLOSE)
838 int const pret = _pclose(inf);
840 #error No pclose() function.
844 perror("RunCommand:: could not terminate child process");
846 return make_pair(pret, ret);
850 FileName const findtexfile(string const & fil, string const & /*format*/)
852 /* There is no problem to extend this function too use other
853 methods to look for files. It could be setup to look
854 in environment paths and also if wanted as a last resort
855 to a recursive find. One of the easier extensions would
856 perhaps be to use the LyX file lookup methods. But! I am
857 going to implement this until I see some demand for it.
861 // If the file can be found directly, we just return a
862 // absolute path version of it.
863 FileName const absfile(makeAbsPath(fil));
864 if (absfile.exists())
867 // Now we try to find it using kpsewhich.
868 // It seems from the kpsewhich manual page that it is safe to use
869 // kpsewhich without --format: "When the --format option is not
870 // given, the search path used when looking for a file is inferred
871 // from the name given, by looking for a known extension. If no
872 // known extension is found, the search path for TeX source files
874 // However, we want to take advantage of the format sine almost all
875 // the different formats has environment variables that can be used
876 // to controll which paths to search. f.ex. bib looks in
877 // BIBINPUTS and TEXBIB. Small list follows:
878 // bib - BIBINPUTS, TEXBIB
880 // graphic/figure - TEXPICTS, TEXINPUTS
881 // ist - TEXINDEXSTYLE, INDEXSTYLE
882 // pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS
884 // tfm - TFMFONTS, TEXFONTS
885 // This means that to use kpsewhich in the best possible way we
886 // should help it by setting additional path in the approp. envir.var.
887 string const kpsecmd = "kpsewhich " + fil;
889 cmd_ret const c = runCommand(kpsecmd);
891 LYXERR(Debug::LATEX, "kpse status = " << c.first << '\n'
892 << "kpse result = `" << rtrim(c.second, "\n\r") << '\'');
894 return FileName(rtrim(to_utf8(from_filesystem8bit(c.second)), "\n\r"));
900 void readBB_lyxerrMessage(FileName const & file, bool & zipped,
901 string const & message)
903 LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
904 // FIXME: Why is this func deleting a file? (Lgb)
910 string const readBB_from_PSFile(FileName const & file)
912 // in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
913 // It seems that every command in the header has an own line,
914 // getline() should work for all files.
915 // On the other hand some plot programs write the bb at the
916 // end of the file. Than we have in the header:
917 // %%BoundingBox: (atend)
918 // In this case we must check the end.
919 bool zipped = file.isZippedFile();
920 FileName const file_ = zipped ? unzipFile(file) : file;
921 string const format = file_.guessFormatFromContents();
923 if (format != "eps" && format != "ps") {
924 readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
928 static lyx::regex bbox_re(
929 "^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
930 ifstream is(file_.toFilesystemEncoding().c_str());
935 if (regex_match(s, what, bbox_re)) {
936 // Our callers expect the tokens in the string
937 // separated by single spaces.
938 // FIXME: change return type from string to something
941 os << what.str(1) << ' ' << what.str(2) << ' '
942 << what.str(3) << ' ' << what.str(4);
943 string const bb = os.str();
944 readBB_lyxerrMessage(file_, zipped, bb);
948 readBB_lyxerrMessage(file_, zipped, "no bb found");
953 int compare_timestamps(FileName const & file1, FileName const & file2)
955 // If the original is newer than the copy, then copy the original
956 // to the new directory.
959 if (file1.exists() && file2.exists()) {
960 double const tmp = difftime(file1.lastModified(), file2.lastModified());
962 cmp = tmp > 0 ? 1 : -1;
964 } else if (file1.exists()) {
966 } else if (file2.exists()) {
974 bool prefs2prefs(FileName const & filename, FileName const & tempfile, bool lfuns)
976 FileName const script = libFileSearch("scripts", "prefs2prefs.py");
977 if (script.empty()) {
978 LYXERR0("Could not find bind file conversion "
979 "script prefs2prefs.py.");
983 ostringstream command;
984 command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
985 << ' ' << (lfuns ? "-l" : "-p") << ' '
986 << quoteName(filename.toFilesystemEncoding())
987 << ' ' << quoteName(tempfile.toFilesystemEncoding());
988 string const command_str = command.str();
990 LYXERR(Debug::FILES, "Running `" << command_str << '\'');
992 cmd_ret const ret = runCommand(command_str);
993 if (ret.first != 0) {
994 LYXERR0("Could not run file conversion script prefs2prefs.py.");
1001 } //namespace support