| 743 | } |
| 744 | |
| 745 | bool SFTPClient::setAttributes(const std::string& path, const SFTPAttributes& input) { |
| 746 | LIBSSH2_SFTP_ATTRIBUTES attrs; |
| 747 | memset(&attrs, 0x00, sizeof(attrs)); |
| 748 | if ((!!(input.flags & SFTP_ATTRIBUTE_UID) != !!(input.flags & SFTP_ATTRIBUTE_GID)) || |
| 749 | (!!(input.flags & SFTP_ATTRIBUTE_MTIME) != !!(input.flags & SFTP_ATTRIBUTE_ATIME))) { |
| 750 | /* Because we can only set these attributes in pairs, we must stat first to learn the other */ |
| 751 | if (!this->stat(path, false /*follow_symlinks*/, attrs)) { |
| 752 | return false; |
| 753 | } |
| 754 | } |
| 755 | attrs.flags = 0U; |
| 756 | if (input.flags & SFTP_ATTRIBUTE_PERMISSIONS) { |
| 757 | attrs.flags |= LIBSSH2_SFTP_ATTR_PERMISSIONS; |
| 758 | attrs.permissions = input.permissions; |
| 759 | } |
| 760 | if (input.flags & SFTP_ATTRIBUTE_UID) { |
| 761 | attrs.flags |= LIBSSH2_SFTP_ATTR_UIDGID; |
| 762 | attrs.uid = input.uid; |
| 763 | } |
| 764 | if (input.flags & SFTP_ATTRIBUTE_GID) { |
| 765 | attrs.flags |= LIBSSH2_SFTP_ATTR_UIDGID; |
| 766 | attrs.gid = input.gid; |
| 767 | } |
| 768 | if (input.flags & SFTP_ATTRIBUTE_MTIME) { |
| 769 | attrs.flags |= LIBSSH2_SFTP_ATTR_ACMODTIME; |
| 770 | attrs.mtime = input.mtime; |
| 771 | } |
| 772 | if (input.flags & SFTP_ATTRIBUTE_ATIME) { |
| 773 | attrs.flags |= LIBSSH2_SFTP_ATTR_ACMODTIME; |
| 774 | attrs.atime = input.atime; |
| 775 | } |
| 776 | |
| 777 | if (libssh2_sftp_stat_ex(sftp_session_, |
| 778 | path.c_str(), |
| 779 | path.length(), |
| 780 | LIBSSH2_SFTP_SETSTAT, |
| 781 | &attrs) != 0) { |
| 782 | last_error_.setLibssh2Error(libssh2_sftp_last_error(sftp_session_)); |
| 783 | logger_->log_debug("Failed to setstat on remote path \"%s\", error: %s", path.c_str(), sftp_strerror(last_error_)); |
| 784 | return false; |
| 785 | } |
| 786 | |
| 787 | return true; |
| 788 | } |
| 789 | |
| 790 | } /* namespace utils */ |
| 791 | } /* namespace minifi */ |
no test coverage detected