]> git.lyx.org Git - lyx.git/blobdiff - src/support/copy.C
remove unused stuff
[lyx.git] / src / support / copy.C
index 2d994b8450e91549589467c5c5b5c30b40fd3e39..9ed6246f417863ae0a1ac9a5085dbacbcdcc7766 100644 (file)
 
 #include <fstream>
 
+#include "support/filename.h"
 #include "support/lyxlib.h"
 
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
 
 namespace lyx {
 
@@ -24,13 +32,36 @@ using std::ios;
 using std::string;
 
 
-bool lyx::support::copy(string const & from, string const & to)
+bool lyx::support::chmod(FileName const & file, unsigned long int mode)
 {
-       ifstream ifs(from.c_str(), ios::binary | ios::in);
+#if defined (HAVE_CHMOD) && defined (HAVE_MODE_T)
+       if (::chmod(file.toFilesystemEncoding().c_str(), mode_t(mode)) != 0)
+               return false;
+#else
+# ifdef WITH_WARNINGS
+#  warning "File permissions are ignored on this system."
+# endif
+#endif
+       return true;
+}
+
+
+bool lyx::support::copy(FileName const & from, FileName const & to, unsigned long int mode)
+{
+       ifstream ifs(from.toFilesystemEncoding().c_str(), ios::binary | ios::in);
        if (!ifs)
                return false;
 
-       ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
+       if (mode != (unsigned long int)-1) {
+               ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
+               if (!ofs)
+                       return false;
+               ofs.close();
+               if (!support::chmod(to, mode))
+                       return false;
+       }
+
+       ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
        if (!ofs)
                return false;