gpt4 book ai didi

c++ - Libzip - 归档错误总是返回 ZIP_ER_OK,即使创建归档失败

转载 作者:行者123 更新时间:2023-11-28 04:49:50 25 4
gpt4 key购买 nike

我正在使用 switch 语句来检查我正在创建的 libzip zip 存档中错误代码的值。但是,它似乎永远不会返回 0 以外的任何内容,即使我故意导致它失败也是如此。 (我试图将文件复制到 100% 满的 USB 驱动器,导致它失败)。

我的用法怎么不对?

                int error = 0;
zip_t * zip = zip_open(externalDevicePath.c_str(), ZIP_CREATE, &error);
zip_add_dir(zip,(institutionId + DIR_SLASH + userId).c_str());

string instAndUserPath = basePath + DIR_SLASH + institutionId + DIR_SLASH + userId;
string stbackupPath = basePath + DIR_SLASH + "STBackups";

ESFileUtilsCommon::addDirectoryToZip(instAndUserPath,zip,(institutionId + DIR_SLASH + userId).c_str());
ESFileUtilsCommon::addDirectoryToZip(stbackupPath,zip,"STBackups");
ESFileUtilsCommon::addDirectoryContentsToZip(basePath, zip);

zip_close(zip);

switch (error){
case ZIP_ER_OK:
mapper.setResult(RESULT_SUCCESS);
retval = CefV8Value::CreateString(mapper.getMappedJsonResponse());
return true;
break;
default:
mapper.setResult(RESULT_FAILURE);
retval = CefV8Value::CreateString(mapper.getMappedJsonResponse());
return false;
break;
}

最佳答案

您还没有提供 Minimal, Complete, and Verifiable example ,所以我们无法测试您的代码。但是,从您在 zip_open 很久之后检查 error 的事实来看,我认为您对 error 在 libzip 中的工作方式感到困惑。

您传递给 zip_openint error 只对 zip_open 负责,任何之后的潜在错误。如果你想知道zip_dir_add是否有错误,你需要检查它自己的返回值,看它的文档:https://libzip.org/documentation/zip_dir_add.html .您还可以使用 zip_get_error() 函数来检查最新的错误,请参阅文档:https://libzip.org/documentation/zip_get_error.html .

关于c++ - Libzip - 归档错误总是返回 ZIP_ER_OK,即使创建归档失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48467735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com