Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/commonstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,21 @@ struct FileTransResponse {
int32 id { -1 };
fastring name;
int32 result { -1 };
bool not_enough { false };

void from_json(const co::Json& _x_) {
id = (int32)_x_.get("id").as_int64();
name = _x_.get("name").as_c_str();
result = (int32)_x_.get("result").as_int64();
not_enough = _x_.get("not_enough").as_bool();
}

co::Json as_json() const {
co::Json _x_;
_x_.add_member("id", id);
_x_.add_member("name", name);
_x_.add_member("result", result);
_x_.add_member("not_enough", not_enough);
return _x_;
}
};
Expand Down
17 changes: 13 additions & 4 deletions src/plugins/daemon/core/service/fsadapter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -11,6 +11,8 @@
#include "co/log.h"
#include "co/path.h"

#include <cerrno>

//using namespace deamon_core;

FSAdapter::FSAdapter(QObject *parent)
Expand Down Expand Up @@ -81,20 +83,24 @@ bool FSAdapter::newFileByFullPath(const char *fullpath, bool isdir)
return fs::exists(fullpath);
}

bool FSAdapter::writeBlock(const char *name, int64 seek_len, const char *data, size_t size)
bool FSAdapter::writeBlock(const char *name, int64 seek_len, const char *data, size_t size, bool *not_enough)
{
fs::file fx(name, 'm');
if (!fx.exists()) {
ELOG << "writeBlock File does not exist: " << name;
return false;
}

bool write = true;
size_t wirted_size = 0;
size_t rem_size = size;
fx.seek(seek_len);
do {
size_t wsize = fx.write(data, rem_size);
if (wsize <= 0) {
write = false;
if (not_enough && (errno == ENOSPC || errno == EFBIG))
*not_enough = true;
ELOG << "fx write done: " << rem_size << " => " << wsize;
break;
}
Expand All @@ -103,11 +109,12 @@ bool FSAdapter::writeBlock(const char *name, int64 seek_len, const char *data, s
} while (wirted_size < size);
fx.close();

return true;
return write;
}

bool FSAdapter::writeBlock(const char *name, int64 seek_len,
const char *data, size_t size, const int flags, fs::file **fx)
const char *data, size_t size, const int flags, fs::file **fx,
bool *not_enough)
{
if (flags & JobTransFileOp::FIlE_CREATE) {
if ((*fx) != nullptr) {
Expand Down Expand Up @@ -143,6 +150,8 @@ bool FSAdapter::writeBlock(const char *name, int64 seek_len,
size_t wsize = (*fx)->write(data, rem_size);
if (wsize <= 0) {
write = false;
if (not_enough && (errno == ENOSPC || errno == EFBIG))
*not_enough = true;
ELOG << "fx write done: " << rem_size << " => " << wsize;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/daemon/core/service/fsadapter.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -21,9 +21,9 @@ class FSAdapter : public QObject
static int getFileEntry(const char *path, FileEntry **entry);
static bool newFile(const char *path, bool isdir);
static bool newFileByFullPath(const char *fullpath, bool isdir);
static bool writeBlock(const char *name, int64 seek_len, const char *data, size_t size);
static bool writeBlock(const char *name, int64 seek_len, const char *data, size_t size, bool *not_enough = nullptr);
static bool writeBlock(const char *name, int64 seek_len, const char *data, size_t size,
const int flags, fs::file **fx);
const int flags, fs::file **fx, bool *not_enough = nullptr);
static bool reacquirePath(fastring filepath, fastring *newpath);

signals:
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/daemon/core/service/job/transferjob.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -706,13 +706,16 @@ bool TransferJob::writeAndCreateFile(const QSharedPointer<FSDataBlock> block, co
// << " flags !!! " << block->flags;
int count = 3;
bool good = false;
bool not_enough = false;
do {
good = FSAdapter::writeBlock(fullpath.c_str(), offset, buffer.c_str(), len, block->flags, &fx);
good = FSAdapter::writeBlock(fullpath.c_str(), offset, buffer.c_str(), len, block->flags, &fx, &not_enough);
count--;
} while(!good && count > 0);


if (!good) {
if (not_enough)
_device_not_enough = true;
ELOG << "file : " << fullpath << " write BLOCK error";
} else {
if (len == 0 && block->flags & JobTransFileOp::FIlE_CREATE) {
Expand Down Expand Up @@ -754,7 +757,7 @@ bool TransferJob::sendToRemote(const QSharedPointer<FSDataBlock> block)
transres.from_json(resJson);
if (transres.result == IO_ERROR) {
DLOG << "remote return: IO_ERROR!";
_device_not_enough = block->flags & JobTransFileOp::FILE_COUNTED;
_device_not_enough = transres.not_enough;
return false;
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/daemon/core/service/jobmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ bool JobManager::handleFSData(const co::Json &info, fastring buf, FileTransRespo
if (!job.isNull()) {
job->pushQueque(datablock);
if (datablock->flags & JobTransFileOp::FILE_COUNTED && job->freeBytes() < datablock->data_size) {
if (reply)
reply->not_enough = true;
return false;
} else if (datablock->flags & JobTransFileOp::FIlE_DIR_CREATE || datablock->flags & JobTransFileOp::FIlE_CREATE) {
co::sleep(10);
Expand Down
Loading