D27871: sftp: fix seekPos + file resuming when part file is of size 11

Stefan BrĂ¼ns noreply at phabricator.kde.org
Thu Mar 5 15:42:22 GMT 2020


bruns added inline comments.

INLINE COMMENTS

> kio_sftp.cpp:1687
>                  if (pos != sbPart->size) {
> -                    qCDebug(KIO_SFTP_LOG) << "Failed to seek to" << sbPart->size << "bytes in source file. Reason given" << strerror(errno);
> +                    qCDebug(KIO_SFTP_LOG) << "Failed to seek to" << sbPart->size << "bytes in source file. Reason given:" << strerror(errno);
>                      sftp_attributes_free(sb);

You should save errno immediately after QT_LSEEK, otherwise any function may overwrite it. See `man 3 errno`:

> A common mistake is to do
> 
>   if (somecall() == -1) {
>       printf("somecall() failed\n");
>       if (errno == ...) { ... }
>   }
>    
> 
> where errno no longer needs to have the value it had upon return from somecall() (i.e., it may have been changed by the printf(3)).  If the value of errno should be preserved across a library call, it must be saved:
> 
>   if (somecall() == -1) {
>       int errsv = errno;
>       printf("somecall() failed\n");
>       if (errsv == ...) { ... }
>   }
>

> kio_sftp.cpp:1955
>          fd = QT_OPEN( QFile::encodeName(sPart), O_RDWR );  // append if resuming
> -        offset = seekPos(fd, 0, SEEK_END);
> -        if(offset < 0) {
> +        offset = QT_LSEEK(fd, partFile.size(), SEEK_SET);
> +        if (offset != partFile.size()) {

dito

REPOSITORY
  R320 KIO Extras

REVISION DETAIL
  https://phabricator.kde.org/D27871

To: sitter, ngraham, feverfew
Cc: bruns, kde-frameworks-devel, kfm-devel, pberestov, iasensio, fprice, LeGast00n, cblack, MrPepe, fbampaloukas, alexde, GB_2, Codezela, feverfew, meven, michaelh, spoorun, navarromorales, firef, ngraham, andrebarros, emmanuelp, mikesomov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20200305/05fb22a3/attachment.htm>


More information about the kfm-devel mailing list