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

feat: make cli option to prevent file removal after receiving errors.… #26

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

mykola2312
Copy link
Contributor

So, I was tinkering with some embedded device which had only busybox and TFTP client. That time I realized I need minimal but feature-able TFTP server, so I looked up and found your project. Everything was going OK until I stumbled upon troubles with dumping block devices. You see, when program reaches end of available block device, like /dev/mtdblock4, it will throw IO error instead of usual EOF, and when error happens the TFTP daemon deletes file. This is not what I wanted and I realized there is no way to disable file deletion. In the end of the day dump was OK and file deletion is unnecessary in this case.

In this PR I made Config / ClientConfig parse --dont-clean option, which then affects value of clean_on_error variable in Config / ClientConfig structs. When instantiating Worker, there is new param which is clean_on_error. I had to pass it into Worker struct, otherwise I would be stuck with global variable or something.

I also changed tests and checked them to work with new parameter.

Best regards,

… integrate option into Config & ClientConfig and populate to Worker applying required behavior
Copy link
Owner

@altugbakan altugbakan left a comment

Choose a reason for hiding this comment

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

Looks amazing, I just have a few nits.

@@ -130,6 +136,7 @@ impl ClientConfig {
println!(" -u, --upload\t\t\t\tSets the client to upload mode, Ignores all previous download flags");
println!(" -d, --download\t\t\tSet the client to download mode, Invalidates all previous upload flags");
println!(" -rd, --receive-directory <DIRECTORY>\tSet the directory to receive files when in Download mode (default: current working directory)");
println!(" --dont-clean\t\t\t\tWill prevent client from deleting files after receiving errors.");
Copy link
Owner

Choose a reason for hiding this comment

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

Can we make the help text "Prevent client from deleting files after receiving errors" (no ., no Will) in order for it to be more consistent with the remainder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes of course. I spent 15 minutes trying to came up with description and not making bool named "dont-clean"

Copy link
Owner

Choose a reason for hiding this comment

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

haha, maybe something like --keep-on-error is more descriptive? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--keep-on-error

Done

src/config.rs Outdated Show resolved Hide resolved
@mykola2312
Copy link
Contributor Author

Done

Copy link
Owner

@altugbakan altugbakan left a comment

Choose a reason for hiding this comment

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

LGTM!

@altugbakan
Copy link
Owner

I think the tests still use the old flag, that's why it is failing

@mykola2312
Copy link
Contributor Author

Damn I forgot to update tests

@altugbakan altugbakan merged commit f0f0957 into altugbakan:main Jul 17, 2024
2 checks passed
@Mart-Bogdan
Copy link

Why this is hidden by command line flag? Shouldn't it be default behavior to not delete files when user was downloading, not actually deleting stuff?

@altugbakan
Copy link
Owner

This is done when receiving a file fails, so a client sending a file and if there's an error, a cleanup happens, since the file is not complete. This is actually the behaviour of most TFTP servers.

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.

3 participants