]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
Don't use a global variable for avoiding removal of the system temp dir
[lyx.git] / src / support / filetools.C
index b0401e71dd19d5f4ce67dded3e4e134ab6f1725b..2eab4b38cfe46671d588b20cd2697babc3f7c479 100644 (file)
@@ -216,12 +216,13 @@ FileName const fileOpenSearch(string const & path, string const & name,
 
 
 /// Returns a vector of all files in directory dir having extension ext.
-vector<string> const dirList(string const & dir, string const & ext)
+vector<string> const dirList(FileName const & dir, string const & ext)
 {
        // EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
        vector<string> dirlist;
 
-       if (!(fs::exists(dir) && fs::is_directory(dir))) {
+       string const encoded_dir = dir.toFilesystemEncoding();
+       if (!(fs::exists(encoded_dir) && fs::is_directory(encoded_dir))) {
                lyxerr[Debug::FILES]
                        << "Directory \"" << dir
                        << "\" does not exist to DirList." << endl;
@@ -233,11 +234,12 @@ vector<string> const dirList(string const & dir, string const & ext)
                extension += '.';
        extension += ext;
 
-       fs::directory_iterator dit(dir);
+       fs::directory_iterator dit(encoded_dir);
        fs::directory_iterator end;
        for (; dit != end; ++dit) {
                string const & fil = dit->leaf();
                if (suffixIs(fil, extension)) {
+                       // FIXME UNICODE: We need to convert from filesystem encoding to utf8
                        dirlist.push_back(fil);
                }
        }
@@ -386,10 +388,10 @@ FileName const createTmpDir(FileName const & tempdir, string const & mask)
 } // namespace anon
 
 
-bool destroyDir(string const & tmpdir)
+bool destroyDir(FileName const & tmpdir)
 {
        try {
-               return fs::remove_all(tmpdir) > 0;
+               return fs::remove_all(tmpdir.toFilesystemEncoding()) > 0;
        } catch (fs::filesystem_error const & fe){
                lyxerr << "Could not delete " << tmpdir << ". (" << fe.what() << ")" << std::endl;
                return false;
@@ -1081,7 +1083,7 @@ cmd_ret const runCommand(string const & cmd)
 }
 
 
-string const findtexfile(string const & fil, string const & /*format*/)
+FileName const findtexfile(string const & fil, string const & /*format*/)
 {
        /* There is no problem to extend this function too use other
           methods to look for files. It could be setup to look
@@ -1094,8 +1096,9 @@ string const findtexfile(string const & fil, string const & /*format*/)
 
        // If the file can be found directly, we just return a
        // absolute path version of it.
-       if (fs::exists(fil))
-               return makeAbsPath(fil);
+       FileName const absfile(makeAbsPath(fil));
+       if (fs::exists(absfile.toFilesystemEncoding()))
+               return absfile;
 
        // No we try to find it using kpsewhich.
        // It seems from the kpsewhich manual page that it is safe to use
@@ -1125,9 +1128,9 @@ string const findtexfile(string const & fil, string const & /*format*/)
                 << "kpse result = `" << rtrim(c.second, "\n")
                 << '\'' << endl;
        if (c.first != -1)
-               return os::internal_path(rtrim(c.second, "\n\r"));
+               return FileName(os::internal_path(rtrim(c.second, "\n\r")));
        else
-               return string();
+               return FileName();
 }