]> git.tdb.fi Git - builder.git/blobdiff - source/copy.cpp
Use mspio for all I/O operations
[builder.git] / source / copy.cpp
index f8c581bd5664ca123f4f657da77883c7dff1003b..4cb42b707be686f59bd2725f089272f63b4e07d4 100644 (file)
@@ -1,16 +1,16 @@
 /* $Id$
 
 This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-200 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
 #include <errno.h>
-#include <fstream>
-#include <iostream>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/io/file.h>
+#include <msp/io/print.h>
 #include "builder.h"
 #include "copy.h"
 #include "package.h"
@@ -25,7 +25,7 @@ Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d)
 {
        announce(pkg.get_name(), "COPY", dest[-1]);
        if(builder.get_verbose()>=2)
-               cout<<s<<" -> "<<d<<'\n';
+               IO::print("%s -> %s\n", s, d);
 
        if(!builder.get_dry_run())
                worker=new Worker(*this);
@@ -51,36 +51,32 @@ void Copy::Worker::main()
        {
                if(e.get_error_code()!=ENOENT)
                {
-                       cerr<<e.what()<<'\n';
+                       IO::print(IO::cerr, "%s\n", e.what());
                        done=error=true;
                        return;
                }
        }
 
-       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";
+               IO::print(IO::cerr, "%s\n", e.what());
                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=FS::stat(copy.src);
        chmod(copy.dest.str().c_str(), st.st_mode&0777);