Procházet zdrojové kódy

Do not check failbit when copying a file. Reason: Copying an empty file causes

failbit to be set even when there is no error.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@58 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz před 12 roky
rodič
revize
ce3d6aa62f
2 změnil soubory, kde provedl 10 přidání a 14 odebrání
  1. 7
    7
      Common/FileBackup.cpp
  2. 3
    7
      Common/Utility.cpp

+ 7
- 7
Common/FileBackup.cpp Zobrazit soubor

@@ -6,6 +6,8 @@
// This file implements the common functionality for the configuration
// utilities.
#include <iostream>
#include <cerrno>
#include <cstring>
#include <cstdio>
@@ -55,13 +57,10 @@ FileBackup::CopyFile(std::string From, std::string To) {
throw std::runtime_error(Temp);
}
if (!Input.eof()) { // Copy if there are characters.
// Copying an empty file causes
Output << Input.rdbuf(); // failbit to be set.
}
Output << Input.rdbuf();
if (Output.bad() || Output.fail()) {
if (Output.bad()) { // Copying an empty file causes
// failbit to be set.
std::string Temp;
Temp = "Error copying " + From;
@@ -69,6 +68,7 @@ FileBackup::CopyFile(std::string From, std::string To) {
Temp += ": ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
Input.close();
@@ -82,7 +82,7 @@ FileBackup::CopyFile(std::string From, std::string To) {
}
Output.close();
if (!Output) {
if (Output.bad()) {
std::string Temp;
Temp = "Error closing the file " + To;

+ 3
- 7
Common/Utility.cpp Zobrazit soubor

@@ -175,14 +175,10 @@ Utility::Copy(std::string From, std::string To) {
throw std::runtime_error(Temp);
}
if (!Input.eof()) { // Copy if there are characters.
// Copying an empty file causes
Output << Input.rdbuf(); // failbit to be set.
Output << Input.rdbuf();
}
if (Output.bad() || Output.fail()) {
std::string Temp;
if (Output.bad()) { // Copying an empty file causes
std::string Temp; // failbit to be set.
Temp = "Error copying " + From;
Temp += " to " + To;

Načítá se…
Zrušit
Uložit