mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-26 01:03:15 +03:00
sftp: Add support for append in sftp_open()
Signed-off-by: Tilo Eckert <tilo.eckert@flam.de>
This commit is contained in:
committed by
Andreas Schneider
parent
cfe7065ce1
commit
1cc1a352fc
20
src/sftp.c
20
src/sftp.c
@@ -1606,6 +1606,7 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
|
||||
sftp_file handle;
|
||||
ssh_string filename;
|
||||
ssh_buffer buffer;
|
||||
sftp_attributes stat_data;
|
||||
uint32_t sftp_flags = 0;
|
||||
uint32_t id;
|
||||
|
||||
@@ -1639,6 +1640,9 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
|
||||
sftp_flags |= SSH_FXF_TRUNC;
|
||||
if ((flags & O_EXCL) == O_EXCL)
|
||||
sftp_flags |= SSH_FXF_EXCL;
|
||||
if ((flags & O_APPEND) == O_APPEND) {
|
||||
sftp_flags |= SSH_FXF_APPEND;
|
||||
}
|
||||
SSH_LOG(SSH_LOG_PACKET,"Opening file %s with sftp flags %x",file,sftp_flags);
|
||||
id = sftp_get_new_id(sftp);
|
||||
if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
|
||||
@@ -1686,6 +1690,22 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
|
||||
case SSH_FXP_HANDLE:
|
||||
handle = parse_handle_msg(msg);
|
||||
sftp_message_free(msg);
|
||||
if ((flags & O_APPEND) == O_APPEND) {
|
||||
stat_data = sftp_stat(sftp, file);
|
||||
if (stat_data == NULL) {
|
||||
sftp_close(handle);
|
||||
return NULL;
|
||||
}
|
||||
if ((stat_data->flags & SSH_FILEXFER_ATTR_SIZE) != SSH_FILEXFER_ATTR_SIZE) {
|
||||
ssh_set_error(sftp->session,
|
||||
SSH_FATAL,
|
||||
"Cannot open in append mode. Unknown file size.");
|
||||
sftp_close(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->offset = stat_data->size;
|
||||
}
|
||||
return handle;
|
||||
default:
|
||||
ssh_set_error(sftp->session, SSH_FATAL,
|
||||
|
||||
Reference in New Issue
Block a user