]> git.tdb.fi Git - builder.git/blobdiff - source/copy.cpp
Convert all fstreams to IO::Files
[builder.git] / source / copy.cpp
index bdcd0a94a8006ec108c31ecfbea5e3ce7d4d97bc..a08085da42d7c09f9014ccd8c71e1fc749e67c5f 100644 (file)
@@ -6,9 +6,11 @@ Distributed under the LGPL
 */
 
 #include <errno.h>
-#include <fstream>
 #include <iostream>
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
+#include <msp/io/file.h>
 #include "builder.h"
 #include "copy.h"
 #include "package.h"
@@ -16,7 +18,7 @@ Distributed under the LGPL
 using namespace std;
 using namespace Msp;
 
-Copy::Copy(Builder &b, const Package &pkg, const Path &s, const Path &d):
+Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d):
        InternalAction(b),
        src(s),
        dest(d)
@@ -38,7 +40,7 @@ Copy::Worker::Worker(Copy &c):
 
 void Copy::Worker::main()
 {
-       mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
+       FS::mkpath(FS::dirname(copy.dest), 0755);
 
        try
        {
@@ -55,32 +57,28 @@ void Copy::Worker::main()
                }
        }
 
-       ifstream in(copy.src.str().c_str());
-       if(!in)
+       try
        {
-               cerr<<"Can't open "<<copy.src<<" for reading\n";
-               done=error=true;
-               return;
-       }
+               IO::File in(copy.src.str());
+               IO::File out(copy.dest.str(), IO::M_WRITE);
 
-       ofstream out(copy.dest.str().c_str());
-       if(!out)
+               // Actual transfer loop
+               char buf[16384];
+               while(!in.eof())
+               {
+                       unsigned len=in.read(buf, sizeof(buf));
+                       out.write(buf, len);
+               }
+       }
+       catch(const Exception &e)
        {
-               cerr<<"Can't open "<<copy.dest<<" for writing\n";
+               cerr<<e.what()<<'\n';
                done=error=true;
                return;
        }
 
-       // Actual transfer loop
-       char buf[16384];
-       while(!in.eof())
-       {
-               in.read(buf, sizeof(buf));
-               out.write(buf, in.gcount());
-       }
-
        // Preserve file permissions
-       struct stat st=stat(copy.src);
+       struct stat st=FS::stat(copy.src);
        chmod(copy.dest.str().c_str(), st.st_mode&0777);
 
        done=true;