Commit 3bb84189 authored by Alexander Saoutkin's avatar Alexander Saoutkin
Browse files

Add support for FileJob->truncate() in smb/sftp slaves

Summary: This implements the new method added in D26148 in the sftp/smb slaves.

Test Plan:
Tested sftp locally with truncate. Seems to work.
Haven't tested locally with smb though.

Reviewers: sitter, dfaure, fvogt

Reviewed By: sitter, dfaure, fvogt

Subscribers: kde-frameworks-devel, kfm-devel, ngraham

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D26191
parent bb873a09
......@@ -10,7 +10,7 @@ project(kio-extras VERSION ${RELEASE_SERVICE_VERSION})
include(FeatureSummary)
set(QT_MIN_VERSION "5.11.0")
set(KF5_MIN_VERSION "5.64.0")
set(KF5_MIN_VERSION "5.66.0")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS DBus Network Widgets Svg)
find_package(Qt5Test ${QT_MIN_VERSION} CONFIG QUIET)
......
......@@ -249,6 +249,10 @@ void sftpProtocol::virtual_hook(int id, void *data)
QUrl *url = static_cast<QUrl *>(data);
fileSystemFreeSpace(*url);
} break;
case SlaveBase::Truncate: {
auto length = static_cast<KIO::filesize_t *>(data);
truncate(*length);
} break;
default:
SlaveBase::virtual_hook(id, data);
}
......@@ -1470,6 +1474,30 @@ void sftpProtocol::seek(KIO::filesize_t offset) {
position(sftp_tell64(mOpenFile));
}
void sftpProtocol::truncate(KIO::filesize_t length) {
qCDebug(KIO_SFTP_LOG) << "truncate, length =" << length;
Q_ASSERT(mOpenFile);
int errorCode = 0;
sftp_attributes attr = sftp_fstat(mOpenFile);
if (attr) {
attr->size = length;
if (sftp_setstat(mSftp, mOpenUrl.path().toUtf8().constData(), attr) == 0) {
truncated(length);
} else {
errorCode = toKIOError(sftp_get_error(mSftp));
}
sftp_attributes_free(attr);
} else {
errorCode = toKIOError(sftp_get_error(mSftp));
}
if (errorCode) {
error(errorCode == KIO::ERR_INTERNAL ? KIO::ERR_CANNOT_TRUNCATE : errorCode, mOpenUrl.path());
closeWithoutFinish();
}
}
void sftpProtocol::close() {
closeWithoutFinish();
......
......@@ -61,6 +61,7 @@ public:
void read(KIO::filesize_t size) override;
void write(const QByteArray &data) override;
void seek(KIO::filesize_t offset) override;
void truncate(KIO::filesize_t length);
void close() override;
void special(const QByteArray &data) override;
......
......@@ -10,6 +10,7 @@ makedir=true
deleting=true
moving=true
opening=true
truncating=true
linking=true
copyToFile=true
copyFromFile=true
......
......@@ -92,6 +92,10 @@ void SMBSlave::virtual_hook(int id, void *data) {
QUrl *url = static_cast<QUrl *>(data);
fileSystemFreeSpace(*url);
} break;
case SlaveBase::Truncate: {
auto length = static_cast<KIO::filesize_t *>(data);
truncate(*length);
} break;
default: {
SlaveBase::virtual_hook(id, data);
} break;
......
......@@ -260,6 +260,7 @@ public:
void read( KIO::filesize_t bytesRequested ) override;
void write( const QByteArray &fileData ) override;
void seek( KIO::filesize_t offset ) override;
void truncate( KIO::filesize_t length );
void close() override;
// Functions not implemented (yet)
......
......@@ -297,6 +297,18 @@ void SMBSlave::seek(KIO::filesize_t offset)
}
}
void SMBSlave::truncate(KIO::filesize_t length)
{
off_t res = smbc_ftruncate(m_openFd, static_cast<off_t>(length));
if (res < 0) {
error(KIO::ERR_CANNOT_TRUNCATE, m_openUrl.path());
closeWithoutFinish();
} else {
qCDebug( KIO_SMB ) << "res" << res;
truncated(length);
}
}
void SMBSlave::closeWithoutFinish()
{
smbc_close(m_openFd);
......
......@@ -26,6 +26,7 @@
"output": "filesystem",
"protocol": "smb",
"opening": true,
"truncating": true,
"reading": true,
"writing": true
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment