Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truncate existing files on sftp write #269

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

rmynar
Copy link
Contributor

@rmynar rmynar commented Feb 15, 2024

In our use case we create a backup of a config file, modify the config file (adding characters), perform testing and restore the original config from backup. We use sftp to read and write the backup. However the restore (sftp_write) ends with damaged config file. Damaged file consists of original content and few characters remained from modified file.

Adding flag LIBSSH2_FXF_TRUNC should solve the problem by truncating existing files.
see: https://libssh2.org/libssh2_sftp_open_ex.html

Copy link
Contributor

@lpramuk lpramuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing file before writing will resolve issue with successive writes to the same file.
Good catch @rmynar !

Copy link
Member

@ogajduse ogajduse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, good find, @rmynar.

Only one thing comes to my mind...
@JacobCallahan Would you like to preserve the current behavior by allowing the user to decide whether to truncate the file?

@JacobCallahan
Copy link
Member

@ogajduse that's a good suggestion to keep in mind for the future if needed, but would complicate the current design a bit. Let's hold off on that for now and revisit if issues arise from this.

@JacobCallahan JacobCallahan merged commit 0767e25 into SatelliteQE:master Feb 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants