瀏覽代碼

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 年之前
父節點
當前提交
ce3d6aa62f
共有 2 個檔案被更改,包括 10 行新增14 行删除
  1. 7
    7
      Common/FileBackup.cpp
  2. 3
    7
      Common/Utility.cpp

+ 7
- 7
Common/FileBackup.cpp 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存