If sys::copy_file fails, try and remove the target file before throwing an exception
authorTim Mayberry <mojofunk@gmail.com>
Sun, 9 Sep 2007 10:05:16 +0000 (10:05 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Sun, 9 Sep 2007 10:05:16 +0000 (10:05 +0000)
git-svn-id: svn://localhost/ardour2/trunk@2435 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/pbd/filesystem.cc

index f527c9a473b35dee01d5a028e04fe1e99a3bdb1b..84d18cfcd242fc45b54b4bccc620ee7c7a1c6de2 100644 (file)
@@ -149,11 +149,10 @@ rename (const path & from_path, const path & to_path)
        }
 }
 
+// XXX character encoding.
 void
 copy_file(const path & from_path, const path & to_path)
 {
-       // this implementation could use mucho memory
-       // for big files.
        std::ifstream in(from_path.to_string().c_str());
        std::ofstream out(to_path.to_string().c_str());
        
@@ -165,9 +164,9 @@ copy_file(const path & from_path, const path & to_path)
        out << in.rdbuf();
        
        if (!in || !out) {
+               remove (to_path);
                throw filesystem_error(string_compose(_("Could not copy existing file %1 to %2"),
                                        from_path.to_string(), to_path.to_string()));
-               remove (to_path);
        }
 }