|
|
|
@ -170,59 +170,108 @@ void p2pool_api::on_fs_open(uv_fs_t* req)
|
|
|
|
|
buf[0].base = work->buf.data();
|
|
|
|
|
buf[0].len = static_cast<uint32_t>(work->buf.size());
|
|
|
|
|
|
|
|
|
|
const int result = uv_fs_write(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), buf, 1, 0, on_fs_write);
|
|
|
|
|
int result = uv_fs_write(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), buf, 1, -1, on_fs_write);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to write to " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
result = uv_fs_close(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), on_fs_error_cleanup);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to close " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void p2pool_api::on_fs_write(uv_fs_t* req)
|
|
|
|
|
{
|
|
|
|
|
DumpFileWork* work = reinterpret_cast<DumpFileWork*>(req->data);
|
|
|
|
|
int result = static_cast<int>(req->result);
|
|
|
|
|
uv_fs_req_cleanup(req);
|
|
|
|
|
|
|
|
|
|
if (req->result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to write to " << work->tmp_name << ", error " << uv_err_name(static_cast<int>(req->result)));
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to write to " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
}
|
|
|
|
|
else if (result && (static_cast<size_t>(result) < work->buf.size())) {
|
|
|
|
|
work->buf.erase(work->buf.begin(), work->buf.begin() + result);
|
|
|
|
|
|
|
|
|
|
uv_fs_req_cleanup(req);
|
|
|
|
|
uv_buf_t buf[1];
|
|
|
|
|
buf[0].base = work->buf.data();
|
|
|
|
|
buf[0].len = static_cast<uint32_t>(work->buf.size());
|
|
|
|
|
|
|
|
|
|
result = uv_fs_write(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), buf, 1, -1, on_fs_write);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to write to " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
|
|
|
|
|
const int result = uv_fs_close(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), on_fs_close);
|
|
|
|
|
result = uv_fs_close(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), on_fs_error_cleanup);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to close " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = uv_fs_close(uv_default_loop_checked(), &work->req, static_cast<uv_file>(work->fd), on_fs_close);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to close " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void p2pool_api::on_fs_close(uv_fs_t* req)
|
|
|
|
|
{
|
|
|
|
|
DumpFileWork* work = reinterpret_cast<DumpFileWork*>(req->data);
|
|
|
|
|
int result = static_cast<int>(req->result);
|
|
|
|
|
uv_fs_req_cleanup(req);
|
|
|
|
|
|
|
|
|
|
if (req->result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to close " << work->tmp_name << ", error " << uv_err_name(static_cast<int>(req->result)));
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to close " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = uv_fs_rename(uv_default_loop_checked(), &work->req, work->tmp_name.c_str(), work->name.c_str(), on_fs_rename);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to rename " << work->tmp_name << " to " << work->name << ", error " << uv_err_name(result));
|
|
|
|
|
|
|
|
|
|
result = uv_fs_unlink(uv_default_loop_checked(), &work->req, work->tmp_name.c_str(), on_fs_error_cleanup);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to delete " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void p2pool_api::on_fs_rename(uv_fs_t* req)
|
|
|
|
|
{
|
|
|
|
|
DumpFileWork* work = reinterpret_cast<DumpFileWork*>(req->data);
|
|
|
|
|
int result = static_cast<int>(req->result);
|
|
|
|
|
uv_fs_req_cleanup(req);
|
|
|
|
|
|
|
|
|
|
const int result = uv_fs_rename(uv_default_loop_checked(), &work->req, work->tmp_name.c_str(), work->name.c_str(), on_fs_rename);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to rename " << work->tmp_name << " to " << work->name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
|
|
|
|
|
result = uv_fs_unlink(uv_default_loop_checked(), &work->req, work->tmp_name.c_str(), on_fs_error_cleanup);
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to delete " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
delete work;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete work;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void p2pool_api::on_fs_rename(uv_fs_t* req)
|
|
|
|
|
void p2pool_api::on_fs_error_cleanup(uv_fs_t* req)
|
|
|
|
|
{
|
|
|
|
|
DumpFileWork* work = reinterpret_cast<DumpFileWork*>(req->data);
|
|
|
|
|
int result = static_cast<int>(req->result);
|
|
|
|
|
uv_fs_req_cleanup(req);
|
|
|
|
|
|
|
|
|
|
if (req->result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to rename " << work->tmp_name << " to " << work->name << ", error " << uv_err_name(static_cast<int>(req->result)));
|
|
|
|
|
if (result < 0) {
|
|
|
|
|
LOGWARN(4, "failed to cleanup after previous errors " << work->tmp_name << ", error " << uv_err_name(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uv_fs_req_cleanup(req);
|
|
|
|
|
delete work;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|