-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
The move function operation flags are error prone #2682
Comments
Absolutely; this is a good refactoring idea. (The backstory here is essentially the same as the importer options: this made sense when the only alternative was "copy," but we've outlived that old design.) It probably makes sense to do this first, before all of #2629, so the importer can use the same enum. I do think an |
Doing this first and using the same enum for the events was my plan. I didn't notice till now that the importer could also use this refactoring on some functions, good that you mentioned that. I noticed that multiple methods only check the |
Yes, that's a good point—I think that is a holdover from when those were the only two options. Everything else should be considered "copy-like" for the purpose of pruning. |
OK. I have finished most of the refactoring but I'm unsure what to do with Also I thought about changing the [move, copy, link, hardlink] config options in What's your opinion on those two things and what do you want me to do? |
That's a good point. Yes, it is possible for About the configuration option for the |
The move functions in library.py and manipule_files in importer.py where changed to use a single parameter for the file operation instead of multiple boolean flags. A typo in the documentation of the Album.move and Item.move functions confusing True and False when describing the store parameter was fixed as well.
Refactored move functions for clarity according to #2682
Should this issue be closed? Looking in
...with regards to the comment...
...suggests that the solution was successfully implemented?! As for the config option, FWIW I agree that |
Yep! This is done. Refactoring the config (in a backwards compatible way) is of course still an option! |
Problem
As I'm in the process of implementing #2629 I noticed something else: The current move functions are somewhat ambiguous and error prone. According to the code only one of the operations (move, copy, link, hardlink) is possible at a time. So the operation should be passed as a single parameter instead of a set of flags.
Consider the following function call that makes no sense and will lead to errors but looks fine:
A good API should be hard to use incorrectly.
Proposed solution
Define an enum or constants (of either integers or strings) describing the possible operations and change all move functions to accept the operation as a single operator.
For example a enum based solution could look like the following:
If you like the idea just let me know what variant you like most (enum or module wide constants with integer or string values) and I will refactor the code and send you a pull request.
The text was updated successfully, but these errors were encountered: