]> git.lyx.org Git - lyx.git/blobdiff - src/support/fs_extras.C
* support/qstring_helpers.h: erase ucs4_to_qstring() method.
[lyx.git] / src / support / fs_extras.C
index 0be6a708113cd3c6f39dfa0100d767d06a8422b9..450cf903eeb9a6d9cb109581e01d4cc7382278c1 100644 (file)
@@ -14,7 +14,6 @@
 #include "fs_extras.h"
 
 #include <boost/filesystem/config.hpp>
-#include <boost/filesystem/exception.hpp>
 #include <boost/detail/workaround.hpp>
 #include <boost/throw_exception.hpp>
 
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
+#include <cerrno>
 #include <fcntl.h>
 
+
 // BOOST_POSIX or BOOST_WINDOWS specify which API to use.
 # if !defined( BOOST_WINDOWS ) && !defined( BOOST_POSIX )
 #   if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
@@ -96,33 +97,35 @@ void copy_file(path const & source, path const & target, bool noclobber)
        int const infile = ::open(source.string().c_str(), O_RDONLY);
        if (infile == -1) {
                boost::throw_exception(
-                       filesystem_error(
+                       filesystem_path_error(
                                "boost::filesystem::copy_file",
                                source, target,
-                               fs::detail::system_error_code()));
+                               fs::lookup_errno(errno)));
        }
 
-       struct stat source_stat;
-       int const ret = ::fstat(infile, &source_stat);
-       if (ret == -1) {
-               ::close(infile);
+        struct stat source_stat;
+        int const ret = ::fstat(infile, &source_stat);
+        if (ret == -1) {
+               int err = errno;
+                ::close(infile);
                boost::throw_exception(
-                       filesystem_error(
-                               "boost::filesystem::copy_file",
-                               source, target,
-                               fs::detail::system_error_code()));
+                       filesystem_path_error(
+                                "boost::filesystem::copy_file",
+                                source, target,
+                                fs::lookup_errno(err)));
        }
 
        int const flags = O_WRONLY | O_CREAT | (noclobber ? O_EXCL : O_TRUNC);
 
        int const outfile = ::open(target.string().c_str(), flags, source_stat.st_mode);
        if (outfile == -1) {
+               int err = errno;
                ::close(infile);
                boost::throw_exception(
-                       filesystem_error(
+                       filesystem_path_error(
                                "boost::filesystem::copy_file",
                                source, target,
-                               fs::detail::system_error_code()));
+                               fs::lookup_errno(err)));
        }
 
        std::size_t const buf_sz = 32768;
@@ -144,26 +147,31 @@ void copy_file(path const & source, path const & target, bool noclobber)
                }
        }
 
-       ::close(infile);
-       ::close(outfile);
+       int err = errno;
+
+        ::close(infile);
+        ::close(outfile);
 
        if (in == -1 || out == -1)
                boost::throw_exception(
-                       filesystem_error(
+                       filesystem_path_error(
                                "boost::filesystem::copy_file",
                                source, target,
-                               fs::detail::system_error_code()));
+                               fs::lookup_errno(err)));
 #endif
 #ifdef BOOST_WINDOWS
        if (::CopyFile(source.string().c_str(), target.string().c_str(), noclobber) == 0) {
+               // CopyFile is probably not setting errno so this is most
+               // likely wrong.
                boost::throw_exception(
-                       filesystem_error(
+                       filesystem_path_error(
                                "boost::filesystem::copy_file",
                                source, target,
-                               fs::detail::system_error_code()));
+                               fs::lookup_error_code(errno)));
        }
 #endif
 }
 
 }
 }
+