]> git.tdb.fi Git - builder.git/blobdiff - source/copy.cpp
Convert all fstreams to IO::Files
[builder.git] / source / copy.cpp
index f8c581bd5664ca123f4f657da77883c7dff1003b..a08085da42d7c09f9014ccd8c71e1fc749e67c5f 100644 (file)
@@ -6,11 +6,11 @@ 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 "builder.h"
 #include "copy.h"
 #include "package.h"
@@ -57,30 +57,26 @@ 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=FS::stat(copy.src);
        chmod(copy.dest.str().c_str(), st.st_mode&0777);