Sfoglia il codice sorgente

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 12 anni fa
parent
commit
ce3d6aa62f
2 ha cambiato i file con 10 aggiunte e 14 eliminazioni
  1. 7
    7
      Common/FileBackup.cpp
  2. 3
    7
      Common/Utility.cpp

+ 7
- 7
Common/FileBackup.cpp Vedi File

@@ -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 Vedi File

@@ -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;

Loading…
Annulla
Salva