MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / setAttributes

Method setAttributes

extensions/sftp/client/SFTPClient.cpp:745–788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745bool 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 */

Callers 1

processOneMethod · 0.45

Calls 5

statMethod · 0.95
sftp_strerrorFunction · 0.85
c_strMethod · 0.80
lengthMethod · 0.80
log_debugMethod · 0.80

Tested by

no test coverage detected