diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ 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) diff --git a/sftp/kio_sftp.h b/sftp/kio_sftp.h --- a/sftp/kio_sftp.h +++ b/sftp/kio_sftp.h @@ -61,6 +61,7 @@ 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) override; void close() override; void special(const QByteArray &data) override; diff --git a/sftp/kio_sftp.cpp b/sftp/kio_sftp.cpp --- a/sftp/kio_sftp.cpp +++ b/sftp/kio_sftp.cpp @@ -1470,6 +1470,31 @@ 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) { + errorCode = errorCode == KIO::ERR_INTERNAL ? KIO::ERR_CANNOT_TRUNCATE : errorCode; + error(errorCode, mOpenUrl.path()); + closeWithoutFinish(); + } +} void sftpProtocol::close() { closeWithoutFinish(); diff --git a/sftp/sftp.protocol b/sftp/sftp.protocol --- a/sftp/sftp.protocol +++ b/sftp/sftp.protocol @@ -10,6 +10,7 @@ deleting=true moving=true opening=true +truncating=true linking=true copyToFile=true copyFromFile=true diff --git a/smb/kio_smb.h b/smb/kio_smb.h --- a/smb/kio_smb.h +++ b/smb/kio_smb.h @@ -261,6 +261,7 @@ 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 ) override; void close() override; // Functions not implemented (yet) diff --git a/smb/kio_smb_file.cpp b/smb/kio_smb_file.cpp --- a/smb/kio_smb_file.cpp +++ b/smb/kio_smb_file.cpp @@ -297,6 +297,18 @@ } } +void SMBSlave::truncate(KIO::filesize_t length) +{ + off_t res = smbc_ftruncate(m_openFd, static_cast(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); diff --git a/smb/smb.protocol b/smb/smb.protocol --- a/smb/smb.protocol +++ b/smb/smb.protocol @@ -9,6 +9,7 @@ makedir=true deleting=true opening=true +truncating=true moving=true copyToFile=true copyFromFile=true